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();
        }

posted @ 2010-01-05 22:12  Xingsoft  阅读(2320)  评论(0编辑  收藏  举报