Class CursorHelper
Provides utility methods for creating and managing custom cursors with DPI scaling support.
Inheritance
Inherited Members
Namespace: Telerik.WinControls
Assembly: Telerik.WinControls.dll
Syntax
public static class CursorHelper
Remarks
CursorHelper contains static methods for creating custom cursors from bitmaps and managing DPI-aware cursor scaling. It includes functionality for creating cursors with custom hot spots and provides built-in flipped arrow cursors optimized for different DPI settings.
Key features include:
- Custom cursor creation from bitmap images with configurable hot spots
- DPI-aware cursor scaling for high-resolution displays
- Built-in flipped arrow cursor with automatic scaling
- Cursor caching to improve performance and memory usage
- SVG-based cursor generation for crisp rendering at any scale
This class is essential for applications that need custom cursors or DPI-aware cursor behavior, particularly in high-DPI environments where standard cursors may appear too small or pixelated.
Properties
FlippedArrowCursor
Gets a flipped arrow cursor optimized for 96 DPI (standard resolution).
Declaration
public static Cursor FlippedArrowCursor { get; }
Property Value
System.Windows.Forms.Cursor
A System.Windows.Forms.Cursor representing a flipped arrow cursor at standard 96 DPI resolution. |
Remarks
This property provides quick access to a flipped arrow cursor designed for standard DPI settings. The cursor is ideal for indicating reverse or opposite directional operations in the user interface.
For high-DPI scenarios, use GetScaledFlippedArrowCursor(SizeF) instead to ensure proper scaling.
Methods
CursorFromBitmap(Bitmap, Point)
Creates a custom cursor from a bitmap image with the specified hot spot.
Declaration
public static Cursor CursorFromBitmap(Bitmap bitmap, Point hotSpot)
Parameters
System.Drawing.Bitmap
bitmap
The bitmap image to use as the cursor appearance. |
System.Drawing.Point
hotSpot
The point within the bitmap that represents the cursor's active point. |
Returns
System.Windows.Forms.Cursor
A new System.Windows.Forms.Cursor instance created from the bitmap with the specified hot spot. |
Remarks
This method converts a bitmap image into a Windows cursor by:
- Converting the bitmap to an icon handle using GetHicon
- Retrieving and modifying the icon information
- Setting the custom hot spot coordinates
- Creating the final cursor using CreateIconIndirect
The hot spot determines which pixel of the cursor image corresponds to the precise mouse position. For example, an arrow cursor typically has its hot spot at the tip of the arrow.
The caller is responsible for disposing of the returned cursor when it's no longer needed.
GetScaledFlippedArrowCursor(SizeF)
Gets a flipped arrow cursor scaled to the specified DPI scaling factor.
Declaration
public static Cursor GetScaledFlippedArrowCursor(SizeF scaling)
Parameters
System.Drawing.SizeF
scaling
The scaling factor to apply to the cursor (e.g., 1.5 for 150% DPI scaling). |
Returns
System.Windows.Forms.Cursor
A System.Windows.Forms.Cursor representing a flipped arrow cursor scaled for the specified DPI. |
Remarks
This method provides DPI-aware flipped arrow cursors by:
- Loading the cursor from an embedded SVG resource for scalable rendering
- Caching cursors for each unique scaling factor to improve performance
- Calculating the appropriate size and hot spot based on the scaling factor
- Generating a bitmap at the target resolution for crisp appearance
The cursor uses SVG-based rendering to ensure sharp, clean appearance at any DPI setting. The hot spot is automatically scaled to maintain proper cursor behavior across different resolutions.
Cursors are cached per scaling factor, so subsequent calls with the same scaling value return the cached cursor for optimal performance.