如何在 WinForms 中的禁用面板上设置 WaitCursor 光标 [英] How to set WaitCursor cursor over disabled panel in WinForms
本文介绍了如何在 WinForms 中的禁用面板上设置 WaitCursor 光标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试这样做
panel.Enabled = false; // to disable all controls on panel at once
panel.Cursor = Cursors.WaitCursor;
并且调试器显示 panel.Cursor 是 WaitCursor,但是当我将鼠标移到面板上时,光标仍然是箭头.
and debugger shows that panel.Cursor is WaitCursor, but when I move a mouse over the panel, cursor is still Arrow.
panel.Update(); panel.Refresh(); // does not help
那么,如何解决它?
推荐答案
禁用的控件将不会接收 Windows 消息.最简单的方法是保持启用状态并以不同的方式处理禁用".
A disabled control will not receive Windows Messages. Easiest is to keep it enabled and handle "Disabled" a different way.
满足您特定需求的另一种方法是将下面的代码添加到按钮的父级 - 您可以优化例程以仅在需要更改时调用.
An alternative for your specific need is to add the code below on to the button's parent - you can optimize the routine to call only when changes are needed.
this.MouseMove += (s, a) =>
{
if (button2.Bounds.Contains(a.Location))
this.Cursor = Cursors.WaitCursor;
else
this.Cursor = Cursors.Default;
};
这篇关于如何在 WinForms 中的禁用面板上设置 WaitCursor 光标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文