Cursor Class

 

Represents the image used to paint the mouse pointer.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

System.Object
  System.Windows.Forms.Cursor

[<Sealed>]
[<SerializableAttribute>]
[<TypeConverterAttribute(typeof(CursorConverter))>]
type Cursor = 
    class
        interface IDisposable
        interface ISerializable
    end

NameDescription
System_CAPS_pubmethodCursor(IntPtr)

Initializes a new instance of the Cursor class from the specified Windows handle.

System_CAPS_pubmethodCursor(Stream)

Initializes a new instance of the Cursor class from the specified data stream.

System_CAPS_pubmethodCursor(String)

Initializes a new instance of the Cursor class from the specified file.

System_CAPS_pubmethodCursor(Type, String)

Initializes a new instance of the Cursor class from the specified resource with the specified resource type.

NameDescription
System_CAPS_pubpropertySystem_CAPS_staticClip

Gets or sets the bounds that represent the clipping rectangle for the cursor.

System_CAPS_pubpropertySystem_CAPS_staticCurrent

Gets or sets a cursor object that represents the mouse cursor.

System_CAPS_pubpropertyHandle

Gets the handle of the cursor.

System_CAPS_pubpropertyHotSpot

Gets the cursor hot spot.

System_CAPS_pubpropertySystem_CAPS_staticPosition

Gets or sets the cursor's position.

System_CAPS_pubpropertySize

Gets the size of the cursor object.

System_CAPS_pubpropertyTag

Gets or sets the object that contains data about the Cursor.

NameDescription
System_CAPS_pubmethodCopyHandle()

Copies the handle of this Cursor.

System_CAPS_pubmethodDispose()

Releases all resources used by the Cursor.

System_CAPS_pubmethodDraw(Graphics, Rectangle)

Draws the cursor on the specified surface, within the specified bounds.

System_CAPS_pubmethodDrawStretched(Graphics, Rectangle)

Draws the cursor in a stretched format on the specified surface, within the specified bounds.

System_CAPS_pubmethodEquals(Object)

Returns a value indicating whether this cursor is equal to the specified Cursor.(Overrides Object.Equals(Object).)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Overrides Object.Finalize().)

System_CAPS_pubmethodGetHashCode()

Retrieves the hash code for the current Cursor.(Overrides Object.GetHashCode().)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodSystem_CAPS_staticHide()

Hides the cursor.

System_CAPS_pubmethodSystem_CAPS_staticShow()

Displays the cursor.

System_CAPS_pubmethodToString()

Retrieves a human readable string representing this Cursor.(Overrides Object.ToString().)

NameDescription
System_CAPS_puboperatorSystem_CAPS_staticEquality(Cursor, Cursor)

Returns a value indicating whether two instances of the Cursor class are equal.

System_CAPS_puboperatorSystem_CAPS_staticInequality(Cursor, Cursor)

Returns a value indicating whether two instances of the Cursor class are not equal.

NameDescription
System_CAPS_pubinterfaceSystem_CAPS_privmethodISerializable.GetObjectData(SerializationInfo, StreamingContext)

This API supports the product infrastructure and is not intended to be used directly from your code. Serializes the object.

A cursor is a small picture whose location on the screen is controlled by a pointing device, such as a mouse, pen, or trackball. When the user moves the pointing device, the operating system moves the cursor accordingly.

Different cursor shapes are used to inform the user what operation the mouse will have. For example, when editing or selecting text, a Cursors.IBeam cursor is typically displayed. A wait cursor is commonly used to inform the user that a process is currently running. Examples of processes you might have the user wait for are opening a file, saving a file, or filling a control such as a DataGrid, ListBox or TreeView with a large amount of data.

All controls that derive from the Control class have a Cursor property. To change the cursor displayed by the mouse pointer when it is within the bounds of the control, assign a Cursor to the Cursor property of the control. Alternatively, you can display cursors at the application level by assigning a Cursor to the Current property. For example, if the purpose of your application is to edit a text file, you might set the Current property to Cursors.WaitCursor to display a wait cursor over the application while the file loads or saves to prevent any mouse events from being processed. When the process is complete, set the Current property to Cursors.Default for the application to display the appropriate cursor over each control type.

System_CAPS_noteNote

If you call Application.DoEvents before resetting the Current property back to the Cursors.Default cursor, the application will resume listening for mouse events and will resume displaying the appropriate Cursor for each control in the application.

Cursor objects can be created from several sources, such as the handle of an existing Cursor, a standard Cursor file, a resource, or a data stream.

System_CAPS_noteNote

The Cursor class does not support animated cursors (.ani files) or cursors with colors other than black and white.

If the image you are using as a cursor is too small, you can use the DrawStretched method to force the image to fill the bounds of the cursor. You can temporarily hide the cursor by calling the Hide method, and restore it by calling the Show method.

Starting with the .NET Framework 4.5.2, the Cursor will be resized based on the system DPI setting when the app.config file contains the following entry:

<appSettings>
  <add key="EnableWindowsFormsHighDpiAutoResizing" value="true" />
</appSettings>

The following code example displays a form that demonstrates using a custom cursor. The custom Cursor is embedded in the application's resource file. The example requires a cursor contained in a cursor file named MyCursor.cur. To compile this example using the command line, include the following flag: /res:MyCursor.Cur, CustomCursor.MyCursor.Cur

No code example is currently available or this language may not be supported.

The following code example displays customer information in a TreeView control. The root tree nodes display customer names, and the child tree nodes display the order numbers assigned to each customer. In this example, 1,000 customers are displayed with 15 orders each. The repainting of the TreeView is suppressed by using the BeginUpdate and EndUpdate methods, and a wait Cursor is displayed while the TreeView creates and paints the TreeNode objects. This example requires that you have a cursor file named MyWait.cur in the application directory. It also requires a Customer object that can hold a collection of Order objects, and that you have created an instance of a TreeView control on a Form.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 1.1

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show: