BitmapExtensionsToCursorHandle Method

Converts the provided bitmap 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.

Definition

Namespace: KGySoft.Drawing
Assembly: KGySoft.Drawing (in KGySoft.Drawing.dll) Version: 8.1.0
C#
public static CursorHandle ToCursorHandle(
	this Bitmap bitmap,
	Point cursorHotspot = default
)

Parameters

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

Return Value

CursorHandle
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 Bitmap. 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).

Remarks

  Note

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.

  Important

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

Exceptions

PlatformNotSupportedExceptionThis method is supported on Windows only.

See Also