Advertisement
holllowknight

ДЗ: UIElement

Mar 16th, 2020 (edited)
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.03 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Bar
  4. {
  5.     class Program
  6.     {
  7.         const int WidthBar = 10;
  8.         const int Percents = 100;
  9.  
  10.         static void Main(string[] args)
  11.         {
  12.             ShowBar(50, ConsoleColor.Red, 5, 2);
  13.             ShowBar(20, ConsoleColor.Cyan, 5, 3);
  14.         }
  15.  
  16.         static void ShowBar(int percent, ConsoleColor fillingColor, int positionX, int positionY)
  17.         {
  18.             int fullSegments = percent * WidthBar / Percents;
  19.             ConsoleColor defaultColor = Console.BackgroundColor;
  20.             Console.SetCursorPosition(positionX, positionY);
  21.             Console.Write("[");
  22.             Console.BackgroundColor = fillingColor;
  23.             PrintLine(fullSegments, '#');
  24.             Console.BackgroundColor = defaultColor;
  25.             PrintLine(WidthBar - fullSegments, ' ');
  26.             Console.WriteLine("]");
  27.         }
  28.  
  29.         static void PrintLine(int length, char filler)
  30.         {
  31.             for (int i = 0; i < length; i++)
  32.                 Console.Write(filler);
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement