rendered paste bodyprivate static void DrawPercent( int percent )
{
int oldX = Console.CursorLeft;
int oldY = Console.CursorTop;
int totalblocks = 20;
int blocks = percent / 5;
int remainingblocks = totalblocks - blocks;
Console.SetCursorPosition( 0, oldY + 1 );
Console.Write( "[" );
for( int i = 0; i < blocks; i++ )
DrawBlock( percent );
for( int i = 0; i < remainingblocks; i++ )
Console.Write( "=" );
Console.Write( "]{0}%", percent );
Console.SetCursorPosition( oldX, oldY );
}
private static void DrawBlock( int percent )
{
ConsoleColor oldColor = Console.BackgroundColor;
Console.BackgroundColor = GetColor( percent );
Console.Write( " " );
Console.BackgroundColor = oldColor;
}
private static ConsoleColor GetColor( int percent )
{
if( percent < 20 )
return ConsoleColor.DarkRed;
else if( percent < 40 )
return ConsoleColor.Red;
else if( percent < 60 )
return ConsoleColor.Yellow;
else if( percent < 80 )
return ConsoleColor.Green;
else
return ConsoleColor.Blue;
}