更改鼠标指针,需要使用到 Windows API:

1. 添加命名空间的引用:

using System.Runtime.InteropServices; 
using System.Reflection;

2. 声明 API 函数

[DllImport("user32.dll")] 
static extern IntPtr LoadCursorFromFile( string fileName );

3. 在Form_Load 事件中,加载自定义光标

private void Form1_Load(object sender, EventArgs e)
  {
      Cursor customCursor = new Cursor(Cursor.Current.Handle);
      IntPtr customCursorHandle = LoadCursorFromFile("你的自定义鼠标指针的路径");
      customCursor.GetType().InvokeMember("handle", BindingFlags.Public |
      BindingFlags.NonPublic | BindingFlags.Instance |
      BindingFlags.SetField, null, customCursor,
     new object[] { customCursorHandle });
     this.Cursor = customCursor;
  }

 

版权声明:本文为edangame原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/edangame/p/6943900.html