|
|
Title | Make a console window clear the console window in VB .NET |
Description | This example shows how to make a console window clear the console window in VB .NET. |
Keywords | console application, console window, clear, console, VB.NET |
Categories | VB.NET, Windows |
|
|
See Knowledge Base article 319239: HOW TO: Clear the Console Window with Visual Basic .NET.
The ConsoleClearer class's Clear method clears the console. It gets a handle to stdout, gets information about the console screen buffer, fills the buffer with spaces, and then places the cursor in the upper left corner.
|
|
' Subroutine used to clear the Console screen.
Public Sub Clear()
Dim hConsoleHandle As IntPtr
Dim hWrittenChars As IntPtr
Dim strConsoleInfo As CONSOLE_SCREEN_BUFFER_INFO
Dim strOriginalLocation As COORD
' Get Handle for standard output
hConsoleHandle = GetStdHandle(STD_OUTPUT_HANDLE)
' Get information about the standard output buffer of
' the Console
GetConsoleScreenBufferInfo(hConsoleHandle, _
strConsoleInfo)
' Fill output buffer with Empty characters (ASCII 32)
FillConsoleOutputCharacter(hConsoleHandle, EMPTY, _
strConsoleInfo.dwSize.X * strConsoleInfo.dwSize.Y, _
strOriginalLocation, hWrittenChars)
' Set the Console cursor back to the origin
SetConsoleCursorPosition(hConsoleHandle, _
strOriginalLocation)
End Sub
|
|
|
|
|
|