浏览后,我有一个代码可以通过使用 C# 给出坐标来以编程方式控制鼠标的移动。我想做同样的事情,但鼠标指针应该用点图像代替。我无法得到它...所以请让我知道 C# 中是否有任何方法...
提前致谢:)
最佳答案
这是一个great tutorial它向您展示了如何做到这一点。
更新
正如 Hans Passant 提醒我的那样,有更好的方法。这是他的版本,摘自 this Stack Overflow Post :
using System;
using System.ComponentModel;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Reflection;
static class NativeMethods {
public static Cursor LoadCustomCursor(string path) {
IntPtr hCurs = LoadCursorFromFile(path);
if (hCurs == IntPtr.Zero) throw new Win32Exception();
var curs = new Cursor(hCurs);
// Note: force the cursor to own the handle so it gets released properly
var fi = typeof(Cursor).GetField("ownHandle", BindingFlags.NonPublic | BindingFlags.Instance);
fi.SetValue(curs, true);
return curs;
}
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern IntPtr LoadCursorFromFile(string path);
}
这是一个用法示例:
this.Cursor = NativeMethods.LoadCustomCursor(@"c:\windows\cursors\aero_busy.ani");
祝你好运!
关于c# - 如何使用图像作为鼠标指针而不是使用 C# 的默认箭头?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9056135/