在不断报告进度的Windows控制台应用程序中使用C#4如何使屏幕的"重绘"更加流畅?
我想做以下其中一项: - 让它只"重绘"正在改变的屏幕部分(进度部分),并保持原样. - "重绘"整个屏幕,但没有闪烁.
目前我重写了所有文本(应用程序名称等).像这样:
Console.Clear();
WriteTitle();
Console.WriteLine();
Console.WriteLine("Deleting:\t{0} of {1} ({2})".FormatString(count.ToString("N0"), total.ToString("N0"), (count / (decimal)total).ToString("P2")));
Run Code Online (Sandbox Code Playgroud)
这导致了很多闪烁.
Tho*_* Li 16
试试Console.SetCursorPosition.更多详细信息:如何更新C#Windows控制台应用程序中的当前行?
static void Main(string[] args)
{
Console.SetCursorPosition(0, 0);
Console.Write("################################");
for (int row = 1; row < 10; row++)
{
Console.SetCursorPosition(0, row);
Console.Write("# #");
}
Console.SetCursorPosition(0, 10);
Console.Write("################################");
int data = 1;
System.Diagnostics.Stopwatch clock = new System.Diagnostics.Stopwatch();
clock.Start();
while (true)
{
data++;
Console.SetCursorPosition(1, 2);
Console.Write("Current Value: " + data.ToString());
Console.SetCursorPosition(1, 3);
Console.Write("Running Time: " + clock.Elapsed.TotalSeconds.ToString());
Thread.Sleep(1000);
}
Console.ReadKey();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
24376 次 |
| 最近记录: |