My Application sometimes comminucate with a Server in another Thread, while the form should be locked in this time(that means, the user cant fire any Click, KeyDown …. event). In this time, a waitoverlay with a loading circle is showing which blocks any mouse events like click or mousehover.
But the problem is, that the user can fire KeyDown events by pressing keys and the user can also make mouse clicks by pressing enter after navigating to the button with the TAB Key.
I know that Form.Enabled = true; can do the trick, but then the form is looking very ugly. I know also that I could make a bool inaction; and then look at this var in the event handler, but I think theres a better way.
Short Form: How can I block GUI Events like Click or KeyDown from a Form without .Enabled = True?
Any help will be greatly appreciated.
Edit: Solved it by adding this to the overlay control:
protected override bool ProcessKeyMessage(ref Message m)
{
return true;
}
protected override bool ProcessTabKey(bool forward)
{
return true;
}
You may set the
KeyPreviewproperty of the form to false.When the
KeyPreviewis false, the form will not receive key events before the event is passed to the control that has focus. And if you change your focus to some unused control which does not interact with keys, form or any controls waiting for key events will not receive any events.