Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace UIElement_03
- {
- class Program
- {
- static void Main(string[] args)
- {
- int value = 12;
- int maxValue = 20;
- int relativeSize = 10;
- Console.SetCursorPosition(0, 1);
- Console.WriteLine($"Относительный размер полоски: ");
- Console.WriteLine($"{value} от {maxValue} это {value * 100 / maxValue}%. При размере полоски в {relativeSize} ячеек закрашиваем {value * relativeSize / maxValue} ячейки");
- DisplayBar(value, maxValue, relativeSize);
- Console.ReadKey();
- }
- static void DisplayBar(int value, int absoluteSize, int relativeSize, char symbol = ' ')
- {
- int coloredPercent = value * relativeSize / absoluteSize;
- string bar = "";
- for (int i = 0; i < coloredPercent; i++)
- {
- bar += symbol;
- }
- Console.Write('[');
- PaintBackground(ref bar, ConsoleColor.DarkRed);
- bar = "";
- for (int i = coloredPercent; i < relativeSize; i++)
- {
- bar += symbol;
- }
- Console.WriteLine($"{bar}]");
- }
- static void PaintBackground(ref string text, ConsoleColor color)
- {
- ConsoleColor defaultColor;
- defaultColor = Console.BackgroundColor;
- Console.BackgroundColor = color;
- Console.Write(text);
- Console.BackgroundColor = defaultColor;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement