Console::CursorVisible Property
.NET Framework (current version)
Gets or sets a value indicating whether the cursor is visible.
Assembly: mscorlib (in mscorlib.dll)
| Exception | Condition |
|---|---|
| SecurityException | The user does not have permission to perform this action. |
| IOException | An I/O error occurred. |
The effect of a set operation persists until the termination of the application that performs the operation. The cursor visibility reverts to its original value after the application terminates.
This example demonstrates the CursorVisible property. The example makes the cursor visible if the first column of input is a '+' character or invisible if the input is a '-' character.
// This example demonstrates the Console.CursorVisible property. using namespace System; int main() { String^ m1 = "\nThe cursor is {0}.\nType any text then press Enter. " "Type '+' in the first column to show \n" "the cursor, '-' to hide the cursor, " "or lowercase 'x' to quit:"; String^ s; bool saveCursorVisibile; int saveCursorSize; // Console::CursorVisible = true; // Initialize the cursor to visible. saveCursorVisibile = Console::CursorVisible; saveCursorSize = Console::CursorSize; Console::CursorSize = 100; // Emphasize the cursor. for ( ; ; ) { Console::WriteLine( m1, ((Console::CursorVisible == true) ? (String^)"VISIBLE" : "HIDDEN") ); s = Console::ReadLine(); if ( String::IsNullOrEmpty( s ) == false ) if ( s[ 0 ] == '+' ) Console::CursorVisible = true; else if ( s[ 0 ] == '-' ) Console::CursorVisible = false; else if ( s[ 0 ] == 'x' ) break; } Console::CursorVisible = saveCursorVisibile; Console::CursorSize = saveCursorSize; } /* This example produces the following results. Note that these results cannot depict cursor visibility. You must run the example to see the cursor behavior: The cursor is VISIBLE. Type any text then press Enter. Type '+' in the first column to show the cursor, '-' to hide the cursor, or lowercase 'x' to quit: The quick brown fox The cursor is VISIBLE. Type any text then press Enter. Type '+' in the first column to show the cursor, '-' to hide the cursor, or lowercase 'x' to quit: - The cursor is HIDDEN. Type any text then press Enter. Type '+' in the first column to show the cursor, '-' to hide the cursor, or lowercase 'x' to quit: jumps over The cursor is HIDDEN. Type any text then press Enter. Type '+' in the first column to show the cursor, '-' to hide the cursor, or lowercase 'x' to quit: + The cursor is VISIBLE. Type any text then press Enter. Type '+' in the first column to show the cursor, '-' to hide the cursor, or lowercase 'x' to quit: the lazy dog. The cursor is VISIBLE. Type any text then press Enter. Type '+' in the first column to show the cursor, '-' to hide the cursor, or lowercase 'x' to quit: x */
UIPermission
for modifying safe top-level windows and subwindows. Associated enumeration: UIPermissionWindow::SafeTopLevelWindows
.NET Framework
Available since 2.0
Available since 2.0
Show: