C# winform 自定义鼠标图标

   //设置鼠标图标
            Bitmap a = (Bitmap)Bitmap.FromFile("1.png");
            SetCursor(a, new Point(16, 36)); //new Point() 定义鼠标的可用点位置。

 

  //设置鼠标函数
        public void SetCursor(Bitmap cursor, Point hotPoint)
        {
            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.Clear(Color.FromArgb(0, 0, 0, 0));
            g.DrawImage(cursor, cursor.Width - hotX, cursor.Height - hotY, cursor.Width,
            cursor.Height);

            this.Cursor = new Cursor(myNewCursor.GetHicon());

            g.Dispose();
            myNewCursor.Dispose();
        }

你可能感兴趣的:(WinForm)