System.Windows.Forms.Cursor Class

Represents the image used to paint the mouse pointer.

See Also: Cursor Members

Syntax

[System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.CursorConverter))]
[System.ComponentModel.Editor("System.Drawing.Design.CursorEditor, System.Drawing.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(System.Drawing.Design.UITypeEditor))]
public sealed class Cursor : IDisposable, System.Runtime.Serialization.ISerializable

Remarks

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 System.Windows.Forms.DataGrid, System.Windows.Forms.ListBox or System.Windows.Forms.TreeView with a large amount of data.

All controls that derive from the System.Windows.Forms.Control class have a Control.Cursor property. To change the cursor displayed by the mouse pointer when it is within the bounds of the control, assign a System.Windows.Forms.Cursor to the Control.Cursor property of the control. Alternatively, you can display cursors at the application level by assigning a System.Windows.Forms.Cursor to the Cursor.Current property. For example, if the purpose of your application is to edit a text file, you might set the Cursor.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 Cursor.Current property to Cursors.Default for the application to display the appropriate cursor over each control type.

Note:

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

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

Note:

The System.Windows.Forms.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 Cursor.DrawStretched(System.Drawing.Graphics, System.Drawing.Rectangle) method to force the image to fill the bounds of the cursor. You can temporarily hide the cursor by calling the Cursor.Hide method, and restore it by calling the Cursor.Show method.

Requirements

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0