# Posted By

novalis78 on 10/16/09

# Statistics

Viewed 353 times
Favorited by 0 user(s)

# ascii progress bar

/ Published in: C#

Main shows how to use the AsciiProgressBar. Enjoy!

Copy this code and paste it in your HTML
1. /// <summary>
2. /// Paints an ascii progress bar based on the two input values
3. /// </summary>
4. /// <param name="total_size"></param>
5. /// <param name="current_size"></param>
6. public void AsciiProgressBar(int total_size, int current_size)
7. {
8. double percent = 0.0;
9. int count = current_size;
10. string output = "";
11. double onePercent = (total_size / 100.0);
12. percent = System.Math.Round(current_size / onePercent, 2);
13.
14. if (percent >= upping)
15. {
16. upping += 2;
17. }
18. else if(percent < stepsOnScreen)
19. {
20. output = "\r" + percent + "%\t[";
21. for (int f = upping; f < sizeOfBar; f++)
22. output += "_";
23. output += "]";
24. Console.Write("\r + " + output);
25. }
26. else if (percent >= 99.99)
27. {
28. output = "\r" + "DONE!" + "%\t[";
29. for (int i = 0; i <= upping / 2; i++)
30. output += "=";
31. output += ">";
32. output += "]";
33. Console.Write("\r + " + output);
34. }
35. else
36. {
37. output = "\r" + percent + "%\t[";
38. for (int i = 0; i <= upping / 2; i++)
39. output += "=";
40. output += ">";
41. for (int f = upping / 2; f < sizeOfBar; f++)
42. output += "_";
43. output += "]";
44. Console.Write("\r + " + output);
45. }
46.
47. }