1

I'm trying to deal with a problem related to the console's output. I would want to keep the first line, but clear all the remaining output.

I found this link: ClearConsoleLine but it's not exactly ...

So, Is there any function that allow me to giving a line number(in this case line 0) clear the rest of the output?

EDIT: concerning one of the comments, this workaround of course is already used, it is the current state:

        Console.Clear();
        Console.WriteLine("CURRENT WORD DOCUMENT: {0}", docPath); //line I want to keep always as first line

Thank you.

braX
  • 11,506
  • 5
  • 20
  • 33
blfuentes
  • 2,731
  • 5
  • 44
  • 72
  • `I found this link: ClearConsoleLine but it's not exactly ...` Where is the difference in your case? – I4V Aug 16 '13 at 06:48
  • If I have 20 lines, I want to remove 19. I know I could use just a loop to continue to the end clearing each of them, but I was just wondering if there is a function that already does this work. – blfuentes Aug 16 '13 at 06:51
  • you could use Console.Clear(). Store the line you wish to keep a variable, clear the console, and then write the line back in again? – SmithMart Aug 16 '13 at 07:06
  • Of course ... easiest way, but it's not the same, I would want more control over the console's output, not simply clear all and rewrite first line. – blfuentes Aug 16 '13 at 07:18
  • I remember making a windows forms application that had a listbox as it's console output. it would run batch files and read the output into the listbox. to the user it looked like a console window. to me I had control over what the user was shown. this way you could wrap the console(listbox) with the document currently in use, or other static information about the process running. – SmithMart Aug 16 '13 at 07:24

1 Answers1

0

If you do not wish to use a loop like in the other post, you could create your own "clear" function by printing an insane amounts of spaces in a single line, and then bring the cursor back. It's not especially visually striking in the compiler, but you can hide it at the bottom, and it only takes two commands VS the loop.

static void Main(string[] args)
    {
        for (int i = 0; i < 20; i++) Console.WriteLine("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
        Eraser();
        Console.ReadLine();
    }

    static void Eraser()
    {
        Console.SetCursorPosition(0, 1);
        Console.WriteLine(" [' 'X2000] "); //I'm not going to write all the spaces for the sake of this post
        Console.SetCursorPosition(0, 1);                                                                                                  
    }
Hadron
  • 441
  • 3
  • 13