日期:2014-05-18  浏览次数:20819 次

C#自定义鼠标
C#如何自定义鼠标,谢谢!

------解决方案--------------------
C# code
this.Text = "旺旺软件工作室";
            Cursor myCursor = new Cursor(Cursor.Current.Handle);
            IntPtr colorCursorHandle = LoadCursorFromFile(@"C:\normal.cur");//鼠标图标路径
            myCursor.GetType().InvokeMember("handle", BindingFlags.Public |
             BindingFlags.NonPublic | BindingFlags.Instance |
             BindingFlags.SetField, null, myCursor,
             new object[] { colorCursorHandle });
            this.Cursor = myCursor;

------解决方案--------------------
C# code

public partial class Form1 : Form
    {
        [DllImport("user32.dll")]
        public static extern IntPtr LoadCursorFromFile(string fileName);

        [DllImport("user32.dll")]
        public static extern IntPtr SetCursor(IntPtr cursorHandle);

        [DllImport("user32.dll")]
        public static extern uint DestroyCursor(IntPtr cursorHandle);

        public Form1()
        {
            Cursor myCursor = new Cursor(Cursor.Current.Handle);
            IntPtr colorCursorHandle = LoadCursorFromFile(@"C:\001.ani");
            myCursor.GetType().InvokeMember("handle", BindingFlags.Public |
             BindingFlags.NonPublic | BindingFlags.Instance |
             BindingFlags.SetField, null, myCursor,
             new object[] { colorCursorHandle });
            this.Cursor = myCursor;

            InitializeComponent();
        }
    }