How to set WaitCursor cursor over disabled panel in WinForms

て烟熏妆下的殇ゞ 提交于 2019-12-11 03:22:58

问题


I'm trying to do this

panel.Enabled = false; // to disable all controls on panel at once
panel.Cursor = Cursors.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

So, how to fix it?


回答1:


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;
                              };


来源:https://stackoverflow.com/questions/11206392/how-to-set-waitcursor-cursor-over-disabled-panel-in-winforms

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!