Advertisement
OldBeliver

Function_02ver04

Mar 28th, 2021
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.74 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.             DisplayBar(value, maxValue, relativeSize);
  18.  
  19.             Console.ReadKey();
  20.         }
  21.  
  22.         static void DisplayBar(int value, int maxValue, int relativeSize, char symbol = ' ')
  23.         {
  24.             int percent = value * 100 / maxValue;
  25.             int coloredPercent = value * relativeSize / maxValue;
  26.  
  27.             Console.SetCursorPosition(0, 1);
  28.             Console.WriteLine($"Относительный размер полоски: ");
  29.             Console.WriteLine($"{value} от {maxValue} это {percent}%. При размере полоски в {relativeSize} ячеек, закрашиваем {coloredPercent} из них.");
  30.  
  31.             string bar = "";
  32.  
  33.             for (int i = 0; i < coloredPercent; i++)
  34.             {
  35.                 bar += symbol;
  36.             }
  37.  
  38.             Console.Write('[');
  39.             PaintBackground(bar, ConsoleColor.DarkRed);
  40.  
  41.             bar = "";
  42.             for (int i = coloredPercent; i < relativeSize; i++)
  43.             {
  44.                 bar += symbol;
  45.             }
  46.  
  47.             Console.WriteLine($"{bar}]");
  48.         }
  49.  
  50.         static void PaintBackground(string text, ConsoleColor color)
  51.         {
  52.             ConsoleColor defaultColor;
  53.  
  54.             defaultColor = Console.BackgroundColor;
  55.             Console.BackgroundColor = color;
  56.             Console.Write(text);
  57.             Console.BackgroundColor = defaultColor;
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement