Fog Creek Software
g
Discussion Board




Clear the console output

I've Googled and also gone through the .NET Framework's Console class members but I don't seem to find an equivalant of [CMD]tput clear[/CMD] or [CMD]clrscr()[/CMD]. Is there a way I can clear the console ouput using VB.NET?

Sathyaish Chakravarthy
Friday, December 26, 2003

There seems to be a [METHOD]Clear[/METHOD] in the LongHorn prelim. documentation but none that I can find for .NET 1.0.3705.

Sathyaish Chakravarthy
Friday, December 26, 2003

Yes, there doesn't seem to be any way to directly manipulate the contents of .NET consoles. That's probably because they're attachable to text streams.

If it's important to your application you might want to use the Platform SDK functions instead -- Win32 provides all the console functions that you'll ever need, including cursor positioning and directly changing chars & attributes.

But I don't know how you would make Win32 functions operate on a .NET console, if it's at all possible. Perhaps you can convert the window handle somehow?

Chris Nahr
Friday, December 26, 2003

I've developed Win32 console apps too, but to my knowledge, even Win32 does not expose an entry point to clear the console, while it does provide for flushing console buffers.

Sathyaish Chakravarthy
Friday, December 26, 2003

There's no Clear() function but you can directly manipulate the screen buffer to achieve the same effect. To clear the console, either use FillConsoleOutputCharacter with a space character or use ScrollConsoleScreenBuffer to scroll away all existing lines.

Chris Nahr
Friday, December 26, 2003

Thanks for the help. I guess you are right. This guy uses FillConsoleOutputCharacter too.

http://www.vbforums.com/showthread.php?s=&threadid=246654

Sathyaish Chakravarthy
Friday, December 26, 2003

Someone also pointed me a MSKB which seemed to have the answer, if anyone else is also interested.

http://support.microsoft.com/default.aspx?scid=kb;en-us;319239&Product=vbNET

Sathyaish Chakravarthy
Friday, December 26, 2003

*  Recent Topics

*  Fog Creek Home