日期:2014-06-10 浏览次数:20729 次
WinForm代码如下:
1 using System; 2 using System.Reflection; 3 using System.Runtime.InteropServices; 4 using System.Windows.Forms; 5 6 namespace KeleyiColorCursor 7 { 8 public partial class CursorForm : Form 9 { 10 [DllImport("user32.dll")] 11 public static extern IntPtr LoadCursorFromFile(string fileName); 12 13 [DllImport("user32.dll")] 14 public static extern IntPtr SetCursor(IntPtr cursorHandle); 15 16 [DllImport("user32.dll")] 17 public static extern uint DestroyCursor(IntPtr cursorHandle); 18 19 public CursorForm() 20 { 21 InitializeComponent(); 22 Cursor myCursor = new Cursor(Cursor.Current.Handle); 23 string m_cursorFile = @"D:\keleyi\pen_r.cur"; 24 25 //pen_r.cur文件下载地址: 26 //http://down.keleyi.com/files/cursors/pen_r.cur 27 28 29 //或者设为动态光标 30 // m_cursorFile = @"D:\keleyi\dinosau2.ani"; 31 //下载地址: http://down.keleyi.com/files/cursors/dinosau2.ani 32 33 IntPtr colorCursorHandle = LoadCursorFromFile(m_cursorFile); 34 35 36 myCursor.GetType().InvokeMember("handle", BindingFlags.Public | 37 BindingFlags.NonPublic | BindingFlags.Instance | 38 BindingFlags.SetField, null, myCursor, 39 new object[] { colorCursorHandle }); 40 this.Cursor = myCursor; 41 } 42 } 43 }
运行后,如果把光标移入窗体,光标消失了,那是因为没有下载光标文件到特定文件夹。
光标文件下载:http://down.keleyi.com/files/cursors/dinosau2.ani
http://down.keleyi.com/files/cursors/pen_r.cur