Diese Dokumentation wurde archiviert und wird nicht länger gepflegt.

Console.CursorVisible-Eigenschaft

Hinweis: Diese Eigenschaft ist neu in .NET Framework, Version 2.0.

Ruft einen Wert ab, der angibt, ob der Cursor sichtbar ist, oder legt diesen fest.

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)

Eigenschaftenwert

true, wenn der Cursor sichtbar ist, andernfalls false.

AusnahmetypBedingung

SecurityException

Der Benutzer besitzt keine Berechtigung zum Ausführen dieser Aktion.

IOException

Ein E/A-Fehler ist aufgetreten.

Hinweis zu Windows 95, Windows 98, Windows 98 Zweite Ausgabe, Windows Millennium Edition: Der Effekt einer Set-Operation bleibt bis zum Beenden der Anwendung erhalten, die die Operation ausführt. Nach dem Beenden der Anwendung wird der ursprüngliche Anzeigezustand des Cursors wiederhergestellt.

In diesem Beispiel wird die CursorVisible-Eigenschaft veranschaulicht. Im Beispiel wird der Cursor angezeigt, wenn die erste Spalte der Eingabe das Zeichen "+" ist, oder ausgeblendet, wenn die Eingabe das Zeichen "-" ist.

// 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 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

.NET Framework

Unterstützt in: 2.0
Anzeigen: