Console::CursorTop Property
Gets or sets the row position of the cursor within the buffer area.
Assembly: mscorlib (in mscorlib.dll)
| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException | The value in a set operation is less than zero. -or- The value in a set operation is greater than or equal to BufferHeight. |
| SecurityException | The user does not have permission to perform this action. |
| IOException | An I/O error occurred. |
This example demonstrates the CursorLeft and CursorTop properties, and the SetCursorPosition and Clear methods. The example positions the cursor, which determines where the next write will occur, to draw a 5 character by 5 character rectangle using a combination of "+", "|", and "-" strings. Note that the rectangle could be drawn with fewer steps using a combination of other strings.
// This example demonstrates the // Console.CursorLeft and // Console.CursorTop properties, and the // Console.SetCursorPosition and // Console.Clear methods. using namespace System; int origRow; int origCol; void WriteAt( String^ s, int x, int y ) { try { Console::SetCursorPosition( origCol + x, origRow + y ); Console::Write( s ); } catch ( ArgumentOutOfRangeException^ e ) { Console::Clear(); Console::WriteLine( e->Message ); } } int main() { // Clear the screen, then save the top and left coordinates. Console::Clear(); origRow = Console::CursorTop; origCol = Console::CursorLeft; // Draw the left side of a 5x5 rectangle, from top to bottom. WriteAt( "+", 0, 0 ); WriteAt( "|", 0, 1 ); WriteAt( "|", 0, 2 ); WriteAt( "|", 0, 3 ); WriteAt( "+", 0, 4 ); // Draw the bottom side, from left to right. WriteAt( "-", 1, 4 ); // shortcut: WriteAt("---", 1, 4) WriteAt( "-", 2, 4 ); // ... WriteAt( "-", 3, 4 ); // ... WriteAt( "+", 4, 4 ); // Draw the right side, from bottom to top. WriteAt( "|", 4, 3 ); WriteAt( "|", 4, 2 ); WriteAt( "|", 4, 1 ); WriteAt( "+", 4, 0 ); // Draw the top side, from right to left. WriteAt( "-", 3, 0 ); // shortcut: WriteAt("---", 1, 0) WriteAt( "-", 2, 0 ); // ... WriteAt( "-", 1, 0 ); // ... // WriteAt( "All done!", 0, 6 ); Console::WriteLine(); } /* This example produces the following results: +---+ | | | | | | +---+ All done! */
- UIPermission
for modifying safe top-level windows and subwindows. Associated enumeration: UIPermissionWindow::SafeTopLevelWindows
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.