GetBootstrap v2.7.0 Update from GetBootstrap v2.5
I add a progress bar feature in my console application customizer and update the #region
grouping and convert the switch
statement to Dictionary
that suggested in the last version.
For now I need help in reviewing my codes in ProgressBar.cs
. You can also review my source code and contribute in my GitHub if you want. DOWNLOAD GetBootstrap v2.7.0
My objective is to create a progress bar that can be modify to 4 different size (small, normal, medium, and large) and change color.
This is the best code I can make. Any Suggestion?
ProgressBar.cs
public class ProgressBar
{
public int Max { get; set; }
public int Value { get; set; }
public ConsoleColor Color { get; set; }
public ProgressBarSize Size { get; set; }
float _Calculation { get; set; }
public ProgressBar()
{
Max = 100;
Value = 0;
Color = ConsoleColor.Blue;
Size = ProgressBarSize.Normal;
}
public void Increment(int value)
{
Value += value;
if (Value <= Max)
{
SetUpProgressBar();
WriteProgressBar();
}
}
private void WriteProgressBar()
{
ProgressBarSize size = Size;
object valueSize = Convert.ChangeType(size, size.GetTypeCode());
int position = 1;
for (int i = 0; i <= _Calculation * Value; i++)
{
Console.BackgroundColor = Color;
Console.CursorLeft = position++;
Console.Write(" ");
}
for (int i = Value; i <= (int)valueSize + 1; i++)
{
Console.BackgroundColor = ConsoleColor.Gray;
Console.CursorLeft = position++;
Console.Write(" ");
}
WriteProgressBarStatus((int)valueSize);
}
private void WriteProgressBarStatus(int p)
{
Console.CursorLeft = p + 5;
Console.ResetColor();
Console.Write(Value + " of " + Max);
}
private void SetUpProgressBar()
{
ProgressBarSize size = Size;
object valueSize = Convert.ChangeType(size , size.GetTypeCode());
Console.CursorLeft = 0;
Console.Write("|");
Console.CursorLeft = (int)valueSize + 2;
Console.Write("|");
Console.CursorLeft = 1;
_Calculation = ((int)valueSize + 0.0f) / Max;
}
}
public enum ProgressBarSize
{
Small = 20,
Normal = 30,
Medium = 40,
Large = 60
}