private static Cursor InternalCreateCursor(Bitmap bitmap, int xHotSpot, int yHotSpot) { NativeMethods.IconInfo icon = default(NativeMethods.IconInfo); NativeMethods.GetIconInfo(bitmap.GetHicon(), ref icon); icon.xHotspot = xHotSpot; icon.yHotspot = yHotSpot; icon.fIcon = false; SafeIconHandle cursorHandle = NativeMethods.CreateIconIndirect(ref icon); return(CursorInteropHelper.Create(cursorHandle)); }
public static Cursor CursorFromBitmap(Bitmap bitmap, Point hotSpot) { IntPtr hicon = bitmap.GetHicon(); NativeMethods.IconInfo iconInfo = new NativeMethods.IconInfo(); NativeMethods.GetIconInfo(hicon, ref iconInfo); iconInfo.xHotspot = hotSpot.X; iconInfo.yHotspot = hotSpot.Y; iconInfo.fIcon = false; return(new Cursor(NativeMethods.CreateIconIndirect(ref iconInfo))); }
private static Cursor InternalCreateCursor(System.Drawing.Bitmap bmp, int xHotSpot, int yHotSpot) { var iconInfo = new NativeMethods.IconInfo(); NativeMethods.GetIconInfo(bmp.GetHicon(), ref iconInfo); iconInfo.xHotspot = xHotSpot; iconInfo.yHotspot = yHotSpot; iconInfo.fIcon = false; SafeIconHandle cursorHandle = NativeMethods.CreateIconIndirect(ref iconInfo); return CursorInteropHelper.Create(cursorHandle); }
private static Cursor InternalCreateCursor(System.Drawing.Bitmap bmp) { var iconInfo = new NativeMethods.IconInfo(); NativeMethods.GetIconInfo(bmp.GetHicon(), ref iconInfo); iconInfo.xHotspot = 0; iconInfo.yHotspot = 0; iconInfo.fIcon = false; SafeIconHandle cursorHandle = NativeMethods.CreateIconIndirect(ref iconInfo); return(CursorInteropHelper.Create(cursorHandle)); }
//保护: /// <summary> /// 创建鼠标(本方法不允许public,避免内存泄漏) /// </summary> /// <param name="bitmap"></param> /// <param name="xHotSpot"></param> /// <param name="yHotSpot"></param> /// <returns></returns> protected static Cursor InternalCreateCursor(Bitmap bitmap, uint xHotSpot, uint yHotSpot) { var iconInfo = new NativeMethods.IconInfo(); NativeMethods.GetIconInfo(bitmap.GetHicon(), ref iconInfo); iconInfo.xHotspot = xHotSpot; //焦点x轴坐标 iconInfo.yHotspot = yHotSpot; //焦点y轴坐标 iconInfo.fIcon = false; //设置鼠标 SafeIconHandle cursorHandle = NativeMethods.CreateIconIndirect(ref iconInfo); return(CursorInteropHelper.Create(cursorHandle)); }
static Cursor InternalCreateCursor(Bitmap bitmap, int xHotSpot, int yHotSpot) { var iconInfo = new NativeMethods.IconInfo { xHotspot = xHotSpot, yHotspot = yHotSpot, fIcon = false }; NativeMethods.GetIconInfo(bitmap.GetHicon(), ref iconInfo); var cursorHandle = NativeMethods.CreateIconIndirect(ref iconInfo); return(CursorInteropHelper.Create(cursorHandle)); }
private static Cursor InternalCreateCursor(System.Drawing.Bitmap bmp, int xHotspot = 0, int yHotspot = 0) { var iconInfo = new NativeMethods.IconInfo(); var handler = bmp.GetHicon(); NativeMethods.GetIconInfo(handler, ref iconInfo); NativeMethods.DestroyIcon(handler); iconInfo.xHotspot = xHotspot; iconInfo.yHotspot = yHotspot; iconInfo.fIcon = false; var cursorHandle = NativeMethods.CreateIconIndirect(ref iconInfo); return(CursorInteropHelper.Create(cursorHandle)); }
public static Cursor CreateCursor(Bitmap bmp, int xHotSpot, int yHotSpot) { // create icon info struct NativeMethods.IconInfo tmp = new NativeMethods.IconInfo(); IntPtr ptr = bmp.GetHicon(); // call native method to populate icon info struct with icon information from bitmap image NativeMethods.GetIconInfo(ptr, ref tmp); // set hot spot on cursor tmp.xHotspot = xHotSpot; tmp.yHotspot = yHotSpot; // marks image as a cursor rather than an icon tmp.fIcon = false; // native method to return pointer to the new cursor icon ptr = NativeMethods.CreateIconIndirect(ref tmp); return(new Cursor(ptr)); }