Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace CSLightFirst
- {
- class Program
- {
- static void Main()
- {
- DrawBar(20, 100, 0, ConsoleColor.DarkCyan);
- DrawBar(10, 50, 1, ConsoleColor.Red, '#');
- DrawBar(8, 40, 2, ConsoleColor.Blue);
- }
- private static void DrawBar(int value, int percent, int position, ConsoleColor color, char symbol = ' ')
- {
- ConsoleColor defaultColor = Console.BackgroundColor;
- Console.SetCursorPosition(0, position);
- int segmentCount = Convert.ToInt32(value * (percent / 100f));
- Console.Write('[');
- Console.BackgroundColor = color;
- for (int i = 0; i < value; i++)
- {
- if (segmentCount > 0)
- {
- Console.Write(symbol);
- segmentCount--;
- }
- else
- {
- Console.BackgroundColor = defaultColor;
- Console.Write(' ');
- }
- }
- Console.BackgroundColor = defaultColor;
- Console.Write(']');
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement