/// <summary> /// Create a cursor from the supplied bitmap & hotspot coordinates /// </summary> /// <param name="bitmap">Bitmap to create an icon from</param> /// <param name="hotspotX">Hotspot X coordinate</param> /// <param name="hotspotY">Hotspot Y coordinate</param> /// <returns>Cursor</returns> private static Cursor CreateCursor(Bitmap bitmap, int hotspotX, int hotspotY) { using (SafeIconHandle iconHandle = new SafeIconHandle( bitmap.GetHicon())) { IntPtr icon; IconInfo iconInfo = new IconInfo(); User32.GetIconInfo(iconHandle, out iconInfo); iconInfo.xHotspot = hotspotX; iconInfo.yHotspot = hotspotY; iconInfo.fIcon = false; icon = User32.CreateIconIndirect(ref iconInfo); return new Cursor(icon); } }
public static extern bool GetIconInfo(SafeIconHandle iconHandle, out IconInfo iconInfo);