Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- class LoadingBar
- {
- static void Main()
- {
- string stars = new string('*', short.MaxValue / 2);
- string dash = new string('-', short.MaxValue / 2);
- int strSize = stars.Length;
- string[] product = new string[strSize];
- for (int i = 0; i < strSize; i++)
- {
- product[i] = "" + stars[i] + dash[i];
- //drawTextProgressBar(i, strSize);
- DrawProgressBar(i, strSize, 30, '#');
- }
- Console.WriteLine();
- }
- private static void DrawProgressBar(int complete, int maxVal, int barSize, char progressCharacter)
- {
- Console.CursorVisible = false;
- int left = Console.CursorLeft;
- decimal perc = (decimal)complete / (decimal)maxVal;
- int chars = (int)Math.Floor(perc / ((decimal)1 / (decimal)barSize));
- string p1 = String.Empty, p2 = String.Empty;
- for (int i = 0; i < chars; i++) p1 += progressCharacter;
- for (int i = 0; i < barSize - chars; i++) p2 += progressCharacter;
- Console.ForegroundColor = ConsoleColor.Green;
- Console.Write(p1);
- Console.ForegroundColor = ConsoleColor.DarkGreen;
- Console.Write(p2);
- Console.ResetColor();
- Console.Write(" {0}%", (perc * 100).ToString("N2"));
- Console.CursorLeft = left;
- }
- static void drawTextProgressBar(int progress, int total)
- {
- //draw empty progress bar
- Console.CursorLeft = 0;
- Console.Write("["); //start
- Console.CursorLeft = 31;
- Console.Write("]"); //end
- Console.CursorLeft = 1;
- float onechunk = 30.0f; // total;
- //draw filled part
- int position = 1;
- for (int i = 0; i < onechunk * progress; i++)
- {
- Console.BackgroundColor = ConsoleColor.Green;
- Console.CursorLeft = position++;
- Console.Write(" ");
- }
- //draw unfilled part
- for (int i = position; i <= 31; i++)
- {
- Console.BackgroundColor = ConsoleColor.Black;
- Console.CursorLeft = position++;
- Console.Write(" ");
- }
- //draw totals
- Console.CursorLeft = 35;
- Console.BackgroundColor = ConsoleColor.Black;
- Console.Write(progress.ToString() + " of " + total.ToString() + " "); //blanks at the end remove any excess
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement