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.

Console.CursorSize Property

Gets or sets the height of the cursor within a character cell.

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

public static int CursorSize { get; set; }
/** @property */
public static int get_CursorSize ()

/** @property */
public static void set_CursorSize (int value)

public static function get CursorSize () : int

public static function set CursorSize (value : int)

Not applicable.

Property Value

The size of the cursor expressed as a percentage of the height of a character cell. The property value ranges from 1 to 100.

Exception typeCondition

ArgumentOutOfRangeException

The value specified in a set operation is less than 1 or greater than 100.

SecurityException

The user does not have permission to perform this action.

IOException

An I/O error occurred.

The cursor appearance varies, ranging from a horizontal line at the bottom of the cell when the property value is 1, to completely filling the cell when the property value is 100.

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition Platform Note: In a set operation, the operating system produces an approximation of the specified value. The effect of a set operation persists until the termination of the application that performs the operation. The cursor size reverts to its original value after the application terminates.

This example demonstrates the CursorSize property. The example increases the size of the cursor each time any console key is pressed, then restores the cursor to its original size before terminating.

// This example demonstrates the Console.CursorSize property.
using System;

class Sample 
{
    public static void Main() 
    {
    string m0 = "This example increments the cursor size from 1% to 100%:\n";
    string m1 = "Cursor size = {0}%. (Press any key to continue...)";
    int[] sizes = {1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100};
    int saveCursorSize;
//
    saveCursorSize = Console.CursorSize;
    Console.WriteLine(m0);
    foreach (int size in sizes)
        {
        Console.CursorSize = size;
        Console.WriteLine(m1, size);
        Console.ReadKey();
        }
    Console.CursorSize = saveCursorSize;
    }
}
/*
This example produces the following results:

This example increments the cursor size from 1% to 100%:

Cursor size = 1%. (Press any key to continue...)
Cursor size = 10%. (Press any key to continue...)
Cursor size = 20%. (Press any key to continue...)
Cursor size = 30%. (Press any key to continue...)
Cursor size = 40%. (Press any key to continue...)
Cursor size = 50%. (Press any key to continue...)
Cursor size = 60%. (Press any key to continue...)
Cursor size = 70%. (Press any key to continue...)
Cursor size = 80%. (Press any key to continue...)
Cursor size = 90%. (Press any key to continue...)
Cursor size = 100%. (Press any key to continue...)

*/

// This example demonstrates the Console.CursorSize property.

import System.*;

class Sample
{
    public static void main(String[] args)
    {
        String m0 = "This example increments the cursor size from 1% to 100%:\n";
        String m1 = "Cursor size = {0}%. (Press any key to continue...)";
        int sizes[] =  { 1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 };
        int saveCursorSize;
        //
        saveCursorSize = Console.get_CursorSize();
        Console.WriteLine(m0);

        for (int iCtr = 0; iCtr < sizes.get_Length(); iCtr++) {
            int size = sizes[iCtr];
            Console.set_CursorSize(size);
            Console.WriteLine(m1, System.Convert.ToString(size));
            Console.ReadKey();
        }
        Console.set_CursorSize(saveCursorSize);
    } //main
} //Sample
/*
This example produces the following results:

This example increments the cursor size from 1% to 100%:

Cursor size = 1%. (Press any key to continue...)
Cursor size = 10%. (Press any key to continue...)
Cursor size = 20%. (Press any key to continue...)
Cursor size = 30%. (Press any key to continue...)
Cursor size = 40%. (Press any key to continue...)
Cursor size = 50%. (Press any key to continue...)
Cursor size = 60%. (Press any key to continue...)
Cursor size = 70%. (Press any key to continue...)
Cursor size = 80%. (Press any key to continue...)
Cursor size = 90%. (Press any key to continue...)
Cursor size = 100%. (Press any key to continue...)

*/

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

Community Additions

Show:
© 2014 Microsoft