ProgressBar.Update (Double) Method
Update the progress by percent.
This language is not supported or no code example is available.
Parameters
-
percent
-
double
The processed percentage.
public void Update(double percent)
{
if (enabled == false)
return;
if (Math.Round(percent * 100) <= this.percentage)
return;
int originCursorTop = System.Console.CursorTop;
int originCursorLeft = System.Console.CursorLeft;
ConsoleColor originBackgroundColor = System.Console.BackgroundColor;
ConsoleColor originForegroundColor = System.Console.ForegroundColor;
int width = System.Console.WindowWidth - textWidth;
percentage = (int)Math.Round(percent * 100);
System.Console.SetCursorPosition(0, cursorTop);
System.Console.Write(new string(' ', textWidth));
System.Console.SetCursorPosition(0, cursorTop);
System.Console.Write($"{percentage}%");
System.Console.BackgroundColor = originForegroundColor;
int newCursorLeft = (int)Math.Round(percent * width);
for (int cursor = cursorLeft; cursor < newCursorLeft; cursor++)
{
System.Console.SetCursorPosition(textWidth + cursor, cursorTop);
System.Console.Write(' ');
}
System.Console.BackgroundColor = originBackgroundColor;
System.Console.ForegroundColor = originForegroundColor;
System.Console.CursorTop = originCursorTop;
System.Console.CursorLeft = originCursorLeft;
cursorLeft = newCursorLeft;
}
This language is not supported or no code example is available.
.NET Framework
Supported in: 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
.NET Core
Supported in: 5.0+, 6.0+