控制台应用程序:如何在没有闪烁的情况下更新显示器?

Jos*_* M. 13 console c#-4.0

在不断报告进度的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控制台应用程序中的当前行?

  • 我的控制台应用程序现在绝对华丽,谢谢! (4认同)

Cra*_*art 8

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)


Mar*_*ery 6

我知道这个问题有点老了,但我发现如果你设置Console.CursorVisible = false了闪烁停止.

  • 对我的目的没有帮助。还是有闪烁。:( (2认同)