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
- {
- class Program
- {
- static void Main(string[] args)
- {
- DisplayBar();
- Console.ReadKey();
- }
- static void DisplayBar()
- {
- int currentValue = 40;
- int maximumValue = 50;
- int relativeSizeBar = 10;
- int percent = currentValue * 100 / maximumValue;
- int paintedBarSize = percent * relativeSizeBar / 100;
- string coloredPartOfBar = "";
- string noColoredPartOfBar = "";
- // header
- Console.Write($"Абсолютная длина полоски: ");
- Console.Write($"{currentValue} это {percent}% от {maximumValue}, ");
- Console.WriteLine($"закрашиваем {currentValue} ячеек из {maximumValue}.");
- // абсолютная полоска
- for (int i = 0; i < currentValue; i++)
- {
- coloredPartOfBar += " ";
- }
- Console.SetCursorPosition(0, 2);
- Console.Write('[');
- PaintBackground(coloredPartOfBar, ConsoleColor.DarkRed);
- for (int i = currentValue; i < maximumValue; i++)
- {
- noColoredPartOfBar += " ";
- }
- Console.Write($"{noColoredPartOfBar}]");
- // относительная полоска
- coloredPartOfBar = "";
- noColoredPartOfBar = "";
- Console.SetCursorPosition(0, 4);
- Console.Write($"Относительная длина полоски: ");
- Console.Write($"{currentValue} это {percent}% от {maximumValue}, ");
- Console.WriteLine($"закрашиваем {paintedBarSize} ячеек из {relativeSizeBar}.");
- for (int i = 0; i < paintedBarSize; i++)
- {
- coloredPartOfBar += " ";
- }
- Console.Write('[');
- PaintBackground(coloredPartOfBar, ConsoleColor.DarkYellow);
- for (int i = paintedBarSize; i < relativeSizeBar; i++)
- {
- noColoredPartOfBar += " ";
- }
- Console.Write($"{noColoredPartOfBar}]");
- }
- static void PaintBackground(string text, ConsoleColor color)
- {
- ConsoleColor defaultColor = Console.BackgroundColor;
- Console.BackgroundColor = color;
- Console.Write(text);
- Console.BackgroundColor = defaultColor;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement