Advertisement
NikaBang

UIElement

Oct 13th, 2024 (edited)
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 KB | None | 0 0
  1. using System;
  2.  
  3. internal class Program
  4. {
  5.     static int MaxPercent = 100;
  6.     static int LengthBar = 10;
  7.     static char Sing = '#';
  8.     static char EmtySing = '_';
  9.  
  10.     static void Main(string[] args)
  11.     {
  12.         DrawBar(40, ConsoleColor.Green, 0, 0);
  13.         DrawBar(80, ConsoleColor.Blue, 30, 0);
  14.         Console.ReadKey();
  15.     }
  16.  
  17.     static void DrawBar(int filledPercent, ConsoleColor color, int positionX, int positionY)
  18.     {
  19.         int remainingPoints = filledPercent * LengthBar / MaxPercent;
  20.         int emptyPoints = LengthBar - remainingPoints;
  21.  
  22.         ConsoleColor defaultColor = Console.ForegroundColor;
  23.  
  24.         string bar = "";
  25.  
  26.         FillBar(ref bar, remainingPoints, Sing);
  27.         FillBar(ref bar, emptyPoints, EmtySing);
  28.  
  29.         Console.SetCursorPosition(positionX, positionY);
  30.         Console.Write('[');
  31.         Console.ForegroundColor = color;
  32.         Console.Write(bar);
  33.         Console.ForegroundColor = defaultColor;
  34.         Console.Write(']');
  35.     }
  36.  
  37.     static void FillBar(ref string bar, int cauntPoint, char sing)
  38.     {
  39.         for (int i = 0;i < cauntPoint;i++)
  40.         {
  41.             bar += sing;
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement