This class wraps a Win32 cursor—the image that represents the
mouse pointer. Cursor is a slightly curious class
in that it wraps up both GDI-like functionality and global system
cursor/pointer behavior.
Unlike Win32, .NET cursors are static images—you cannot create
them from animations. You can, however, create cursors from COM
IPicture objects, files and streams, and Win32
cursor handles. You can also retrieve a Win32 handle using the
Handle property, or get a copy of the underlying
Win32 object with the CopyHandle() method.
Predefined cursors are available as static properties on the
Cursors class.
Similar to most of the System.Drawing objects,
Cursor objects are a scarce system resource, and
therefore you should manage their lifetimes carefully, calling
Dispose() when you are finished to release the
resources back to the OS. Also in keeping with the drawing objects,
you can paint the cursor imagery on a
System.Drawing.Graphics surface using the
Draw( ) and DrawStretched()
methods. The object's dimensions can be obtained
from the Size property.
Each Control object has a
Cursor property, which you can use to the set the
default cursor shown while the mouse is over the control. You can
also temporarily set the cursor to something else (such as the
Cursors.WaitCursor) by using the static
Current property. This overrides any other
settings until you either set the Current value
back to Cursors.Default or call the
DoEvents() method.
You can find the screen coordinates at which the cursor is currently
being rendered by using the static Position
property, and the expected dimensions of the system cursor from the
static Clip.
You can also Show() and Hide() the cursor through static methods of those names. If the
cursor is hidden, Current will return null.
public sealed class Cursor : IDisposable, System.Runtime.Serialization.ISerializable {
// Public Constructors
public Cursor(IntPtr handle);
public Cursor(System.IO.Stream stream);
public Cursor(string fileName);
public Cursor(Type type, string resource);
// Public Static Properties
public static Rectangle Clip{set; get; }
public static Cursor Current{set; get; }
public static Point Position{set; get; }
// Public Instance Properties
public IntPtr Handle{get; }
public Size Size{get; }
// Public Static Methods
public static void Hide();
public static void Show();
public static bool operator !=(Cursor left, Cursor right);
public static bool operator ==(Cursor left, Cursor right);
// Public Instance Methods
public IntPtr CopyHandle();
public void Dispose(); // implements IDisposable
public void Draw(System.Drawing.Graphics g, System.Drawing.Rectangle targetRect);
public void DrawStretched(System.Drawing.Graphics g, System.Drawing.Rectangle targetRect);
public override bool Equals(object obj); // overrides object
public override int GetHashCode(); // overrides object
public override string ToString(); // overrides object
// Protected Instance Methods
protected override void Finalize(); // overrides object
}