IconExtensionsToCursorHandle Method

Converts the provided icon to a CursorHandle, which can be passed to the System.Windows.Forms.Cursor constructor to create a new cursor that supports colors and partial transparency.


Namespace: KGySoft.Drawing
Assembly: KGySoft.Drawing (in KGySoft.Drawing.dll) Version: 8.1.0
public static CursorHandle ToCursorHandle(
	this Icon icon,
	Point cursorHotspot = default


icon  Icon
The Icon, which should be converted to a cursor.
cursorHotspot  Point  (Optional)
The hotspot coordinates of the cursor. This parameter is optional.
Default value: 0; 0 (top-left corner)

Return Value

A CursorHandle instance that can be used to create a System.Windows.Forms.Cursor instance.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type Icon. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).



This method is supported on Windows only.

Though the documentation of the System.Windows.Forms.Cursor class states that it does not support cursors with colors other than black and white, by using this method you can create a cursor that supports colors and partial transparency. Just pass the result CursorHandle to the Cursor(IntPtr) constructor.


Do keep a reference to this CursorHandle instance until the cursor is in use; otherwise, the cursor resources might be disposed too soon.


PlatformNotSupportedExceptionThis method is supported on Windows only.

See Also