Advertisement
OldBeliver

Function_02ver03

Mar 27th, 2021
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.73 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace UIElement_03
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int value = 12;
  14.             int maxValue = 20;
  15.             int relativeSize = 10;
  16.  
  17.             Console.SetCursorPosition(0, 1);
  18.             Console.WriteLine($"Относительный размер полоски: ");
  19.             Console.WriteLine($"{value} от {maxValue} это {value * 100 / maxValue}%. При размере полоски в {relativeSize} ячеек закрашиваем {value * relativeSize / maxValue} ячейки");
  20.             DisplayBar(value, maxValue, relativeSize);
  21.  
  22.             Console.ReadKey();
  23.         }
  24.  
  25.         static void DisplayBar(int value, int absoluteSize, int relativeSize, char symbol = ' ')
  26.         {
  27.             int coloredPercent = value * relativeSize / absoluteSize;
  28.             string bar = "";
  29.  
  30.             for (int i = 0; i < coloredPercent; i++)
  31.             {
  32.                 bar += symbol;
  33.             }
  34.  
  35.             Console.Write('[');
  36.             PaintBackground(ref bar, ConsoleColor.DarkRed);
  37.  
  38.             bar = "";
  39.             for (int i = coloredPercent; i < relativeSize; i++)
  40.             {
  41.                 bar += symbol;
  42.             }
  43.  
  44.             Console.WriteLine($"{bar}]");
  45.         }
  46.  
  47.         static void PaintBackground(ref string text, ConsoleColor color)
  48.         {
  49.             ConsoleColor defaultColor;
  50.  
  51.             defaultColor = Console.BackgroundColor;
  52.             Console.BackgroundColor = color;
  53.             Console.Write(text);
  54.             Console.BackgroundColor = defaultColor;
  55.         }
  56.  
  57.     }
  58. }
  59.  
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement