Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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:

I have a logo (I put it on screen using Console.WriteLine()) and a 2d array which I want to keep constant and clear everything below it.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
323 views
Welcome To Ask or Share your Answers For Others

1 Answer

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);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...