c# console, Console.Clear problem

后端 未结 3 1393
忘掉有多难
忘掉有多难 2020-12-14 22:44

I am writing a console program in C#.

Is there a way I can use a Console.Clear() to only clear certain things on the console screen?

Here\'s my issue:

<
3条回答
  •  渐次进展
    2020-12-14 23:14

    You could use a custom method to clear parts of the screen...

    static void Clear(int x, int y, int width, int height)
    {
        int curTop = Console.CursorTop;
        int curLeft = Console.CursorLeft;
        for (; height > 0;)
        {
            Console.SetCursorPosition(x, y + --height);
            Console.Write(new string(' ',width));
        }
        Console.SetCursorPosition(curLeft, curTop);
    }
    

提交回复
热议问题