c# Console Progress Bar
by admin on Jan.27, 2010, under c#
private static void drawTextProgressBar(decimal progress, decimal total)
{
//draw empty progress bar
Console.CursorLeft = 0;
Console.Write(“["); //start
Console.CursorLeft = 32;
Console.Write("]“); //end
Console.CursorLeft = 1;
float onechunk = 30.0f / (int)total;
//draw filled part
int position = 1;
for (int i = 0; i < onechunk * (int)progress; i++)
{
Console.BackgroundColor = ConsoleColor.Green;
Console.CursorLeft = position++;
Console.Write(” “);
}
//draw unfilled part
for (int i = position; i <= 31; i++)
{
Console.BackgroundColor = ConsoleColor.Black;
Console.CursorLeft = position++;
Console.Write(” “);
}
//draw totals
Console.CursorLeft = 34;
Console.BackgroundColor = ConsoleColor.Black;
decimal value = Math.Round ((progress / total) * 100,0);
Console.Write(value.ToString () + “% “); //blanks at the end remove any excess
}