Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
This topic has not yet been rated - Rate this topic

Console.CursorVisible Property

Gets or sets a value indicating whether the cursor is visible.

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

public static bool CursorVisible { get; set; }
/** @property */
public static boolean get_CursorVisible ()

/** @property */
public static void set_CursorVisible (boolean value)

public static function get CursorVisible () : boolean

public static function set CursorVisible (value : boolean)

Not applicable.

Property Value

true if the cursor is visible; otherwise, false.
Exception typeCondition

SecurityException

The user does not have permission to perform this action.

IOException

An I/O error occurred.

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition Platform Note: 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 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

*/


// This example demonstrates the Console.CursorVisible property.
import System.*;

class Sample
{
    public static void main(String[] args)
    {
        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;
        boolean saveCursorVisibile;
        int saveCursorSize;
        //
        Console.set_CursorVisible(true); // Initialize the cursor to visible.
        saveCursorVisibile = Console.get_CursorVisible();
        saveCursorSize = Console.get_CursorSize();
        Console.set_CursorSize(100); // Emphasize the cursor.
        while (true) {
            Console.WriteLine(m1, (Console.get_CursorVisible() == true) ? 
                "VISIBLE" : "HIDDEN");
            s = Console.ReadLine();
            if (String.IsNullOrEmpty(s) == false) {
                if (s.get_Chars(0) == '+') {
                    Console.set_CursorVisible(true);
                }
                else {
                    if (s.get_Chars(0) == '-') {
                        Console.set_CursorVisible(false);
                    }
                    else {
                        if (s.get_Chars(0) == 'x') {
                            break;
                        }
                    }
                }
            }
        }
        Console.set_CursorVisible(saveCursorVisibile);
        Console.set_CursorSize(saveCursorSize);
    } //main
} //Sample 
/*
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

*/

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft. All rights reserved.