有没有办法清除控制台应用程序中的特定行?

时间:2013-04-22 15:30:03

标签: c# methods console console-application clear

我需要在控制台中清除某一行,但需要保留其余部分。 我知道Console.Clear(),但清除了整个控制台。 我该如何清除一行?

1 个答案:

答案 0 :(得分:4)

我已经决定回答我自己的问题了,因为我用谷歌搜索了这个,似乎没有人有方法。

由于没有clearLine()/ ClearLine()方法,我做了一个。

这是:

private static void clearLine()
{
        Console.Write(new string(' ', Console.BufferWidth - Console.CursorLeft));
}

其他可能性:

private static void clearLine(int left, int top)
{    

int pLeft = Console.CursorLeft;
int pTop  = Console.CursorTop;

Console.setCursorPosition(left, top);
Console.Write(new string(' ', Console.BufferWidth - Console.CursorLeft));

Console.setCursorPosition(pLeft, pTop);
}
相关问题