现在的位置: 首页 > 综合 > 正文

C# winform 自定义鼠标图标

2013年05月09日 ⁄ 综合 ⁄ 共 662字 ⁄ 字号 评论关闭

   //设置鼠标图标
            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();
        }

抱歉!评论已关闭.