问题
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