设置 Cursor 属性没有效果
我有一个从 System.Windows.Forms.Panel 派生的类,并且我的应用程序有一个带有这些面板之一的主窗体。总的来说,面板效果很好!我唯一遇到的问题是设置光标。无论我将其设置为 Cursors 类的静态成员之一(Default、WaitCursor 等)还是将其设置为从资源加载的自定义游标,最终结果都是相同的:它不执行任何操作。无论如何,我仍然看到默认的鼠标指针。这行代码位于我的面板派生类的方法内:
this.Cursor = Cursors.WaitCursor;
我可以在那里设置一个断点,并看到该行在我期望的时候被击中。我还为 OnCursorChanged 方法创建了一个重写,并在其中设置了一个断点以查看它是否被触发。我可以验证两个断点是否在我期望的时候被命中。然而,光标永远不会改变。一定有什么东西我错过了。有人有什么想法吗?
PS 我也尝试设置 Current.Cursor ,但这没有帮助。
I have a class that I've derived from System.Windows.Forms.Panel, and my application has a main form with one of these panels. On the whole, the panel works great! The only thing I'm having trouble with is setting the cursor. Whether I'm setting it to one of the static members of the Cursors class (Default, WaitCursor, etc.) or setting it to a custom cursor that I've loaded from a resource, the end result is the same: it does nothing. I still see the default mouse pointer, no matter what. This line of code is inside a method of my panel-derived class:
this.Cursor = Cursors.WaitCursor;
I can set a break point there, and see that this line is being hit when I expect it to. I've also created an override for the OnCursorChanged method, and set a breakpoint in there just to see if it's being triggered. I can verify that both breakpoints are being hit when I expect them to. However, the cursor just never changes. There must be something that I'm missing. Does anyone have any ideas?
P.S. I also did try setting Current.Cursor as well, however that did not help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用游标类的静态属性而不是使用
this.Cursor
:或检查 此线程 了解有关设置光标的更多信息和解决方法。
Try to use the static property of the cursor class instead of using
this.Cursor
:or check this thread for more information and workarounds on setting the cursor.