Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace C_sharp_Light
- {
- class Program
- {
- static void Main(string[] args)
- {
- DrawBar(50, 10, ConsoleColor.Red, 5, 5);
- DrawBar(10, 16, ConsoleColor.Green, 5, 6);
- DrawBar(100, 20, ConsoleColor.Yellow, 5, 7);
- Console.ReadKey();
- }
- static void DrawBar(int fillingPercent, int sizeBar, ConsoleColor color, int xPos, int yPos)
- {
- if (fillingPercent > 100)
- fillingPercent = 100;
- if (fillingPercent < 0)
- fillingPercent = 0;
- int fillingPercentOfBar = sizeBar * fillingPercent / 100;
- Console.SetCursorPosition(xPos, yPos);
- for (int i = 0; i <= sizeBar + 1; i++)
- {
- if (i == 0)
- {
- Console.ForegroundColor = ConsoleColor.White;
- Console.Write('[');
- }
- else if (i == sizeBar + 1)
- {
- Console.ForegroundColor = ConsoleColor.White;
- Console.Write(']');
- }
- else if (i <= fillingPercentOfBar)
- {
- Console.ForegroundColor = color;
- Console.Write('#');
- }
- else
- {
- Console.ForegroundColor = ConsoleColor.White;
- Console.Write('_');
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment