Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Bar
- {
- class Program
- {
- const int WidthBar = 10;
- const int Percents = 100;
- static void Main(string[] args)
- {
- ShowBar(50, ConsoleColor.Red, 5, 2);
- ShowBar(20, ConsoleColor.Cyan, 5, 3);
- }
- static void ShowBar(int percent, ConsoleColor fillingColor, int positionX, int positionY)
- {
- int fullSegments = percent * WidthBar / Percents;
- ConsoleColor defaultColor = Console.BackgroundColor;
- Console.SetCursorPosition(positionX, positionY);
- Console.Write("[");
- Console.BackgroundColor = fillingColor;
- PrintLine(fullSegments, '#');
- Console.BackgroundColor = defaultColor;
- PrintLine(WidthBar - fullSegments, ' ');
- Console.WriteLine("]");
- }
- static void PrintLine(int length, char filler)
- {
- for (int i = 0; i < length; i++)
- Console.Write(filler);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement