Console.WindowTop Property

 

Gets or sets the top position of the console window area relative to the screen buffer.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

static member WindowTop : int with get, set

Property Value

Type: System.Int32

The uppermost console window position measured in rows.

Exception Condition
ArgumentOutOfRangeException

In a set operation, the value to be assigned is less than zero.

-or-

As a result of the assignment, WindowTop plus WindowHeight would exceed BufferHeight.

IOException

Error reading or writing information.

The console represents a rectangular window into a larger rectangular buffer area. Both the window and the buffer are measured vertically by their number of rows and horizontally by their number of columns. The dimensions of the buffer area are defined by the BufferHeight and BufferWidth properties. The dimensions of the console area are defined by the WindowHeight and WindowWidth properties. The WindowTop property determines which row of the buffer area is displayed in the first column of the console window. The value of the WindowTop property can range from 0 to BufferHeight - WindowHeight. Attempting to set it to a value outside that range throws an ArgumentOutOfRangeException.

Attempting to set the value of the WindowTop property when output is redirected throws an IOException exception. To prevent the exception, you can set the value of this property only if the IsOutputRedirected property returns false.

The following example demonstrates the WindowLeft, WindowTop, WindowWidth, WindowHeight, BufferWidth, BufferHeight, and CursorVisible properties; and the SetWindowPosition, SetBufferSize, and ReadKey methods. The example draws a grid pattern in the screen buffer based on the screen buffer width. Then the example moves the console window in response to which of the UP ARROW, DOWN ARROW, LEFT ARROW, or RIGHT ARROW console keys is pressed. The grid pattern helps you see the movement of the console window relative to the screen buffer.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 2.0
Return to top
Show: