Console.CursorVisible Property
Gets or sets a value indicating whether the cursor is visible.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
| Exception | Condition |
|---|---|
| SecurityException | The user does not have permission to perform this action. |
| IOException | An I/O error occurred. |
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 System; class Sample { public static void 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. while(true) { Console.WriteLine(m1, ((Console.CursorVisible == true) ? "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
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.