Cursors.Hand 不显示链接选择光标
我的项目中有以下代码,用于当用户将鼠标悬停在自定义按钮上时更改鼠标光标:
protected override void OnMouseEnter(EventArgs e)
{
this.Cursor = Cursors.Hand;
base.OnMouseEnter(e);
}
protected override void OnMouseLeave(EventArgs e)
{
this.Cursor = Cursors.Default;
base.OnMouseLeave(e);
}
这工作正常,只是显示的光标是标准的白色手形光标。但在 Windows XP 的鼠标属性中,我将链接选择光标设置为动画彩色箭头。
为了调查这个问题,我在“鼠标属性”中将动画箭头设置为“忙碌”光标,并将“OnMouseEnter”中的代码更改为:
this.Cursor = Cursors.WaitCursor;
这按我的预期工作,并且显示了箭头。
似乎 Cursors.Hand
与鼠标属性中的链接选择光标不对应。但我找不到更适合在 Cursors 类中使用的内容。我做错了什么?
I have the following code in my project to change mouse cursor when the user is hovering over a custom button:
protected override void OnMouseEnter(EventArgs e)
{
this.Cursor = Cursors.Hand;
base.OnMouseEnter(e);
}
protected override void OnMouseLeave(EventArgs e)
{
this.Cursor = Cursors.Default;
base.OnMouseLeave(e);
}
This works fine, except that the cursor that is shown is the standard white hand cursor. But in Mouse Properties in Windows XP I have set the Link Select cursor to be an animated colorful arrow.
To investigate the problem I set the animated arrow as the Busy cursor in Mouse Properties and changed the code in OnMouseEnter
to:
this.Cursor = Cursors.WaitCursor;
This works as I expected and the arrow was shown.
It seems like Cursors.Hand
does not correspond to the Link Select cursor in Mouse Properties. But I can't find anything more appropriate to use in the Cursors
class. What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
.NET框架为
Cursor.Hand
提供了自己的光标;它不会从操作系统加载用户选择的光标。我只能想象这是因为运行.NET 的Windows NT 4 不提供“手”光标。这是 Windows 98 和 2000 中添加的一项功能。针对 Windows 95 或 NT 4 的应用程序会在需要时提供自己的手形光标。
好消息是解决方法相对简单。这是相当少量的互操作。您只需将
LoadCursor
与IDC_HAND
结合使用,然后将返回的句柄传递给Cursor
类的构造函数。The .NET framework provides its own cursor for
Cursor.Hand
; it doesn't load the user-selected cursor from the operating system.I can only imagine that this is because Windows NT 4, on which .NET will run, does not provide a "hand" cursor. It was a feature added in Windows 98 and 2000. Applications which target Windows 95 or NT 4 provide their own hand cursor if they need one.
The good news is that the workaround is relatively simple. It's a fairly small amount of interop. You just need to use
LoadCursor
withIDC_HAND
, then pass the returned handle to the constructor for theCursor
class.