public void SetCursor(Bitmap cursor, Point hotPoint)//移动自定义光标的图象位置,使他在0 0点起作用 { try { int hotX = hotPoint.X; int hotY = hotPoint.Y; Bitmap myNewCursor = new Bitmap(cursor.Width * 2 - hotX, cursor.Height * 2 - hotY); Graphics g = Graphics.FromImage(myNewCursor); g.DrawImage(cursor, cursor.Width - hotX, cursor.Height - hotY, cursor.Width, cursor.Height); theImage.Cursor = new Cursor(myNewCursor.GetHicon()); g.Dispose(); } catch(Exception ex) { } }
调用方法
Cursor obj = new Cursor(curbmp.GetHicon()); SetCursor(curbmp, obj.HotSpot);//目前遇到的自定义光标是在中间位置