Disabling a control from receiving an event in C #
I have a dialog with many controls. Each evey control will be populated during the boot sequence and may take some time to fill. While I am not , I want the user to click on any of the controls. In other words, I want to disable the control from receiving events, and I do not want to disable the controls (as that might seem strange). Also I don't want to subscribe and unsubscribe from regular intervals. Is there a way to stop the control over listening for events for a short time?
Sudarshan Srinivasan
The whole point of disabling controls is to inform the user that the control cannot be used at a specific time. This is a convention that users have come to know and are used to, so I would suggest following this. Not doing this can confuse users.
The easiest way is to disable the container that contains the controls, rather than disable each control. The best way (or at least what I prefer) is to have a method that will manipulate the properties of the controls Visible
and Enabled
based on what state the UI is in.
source to share
The easiest way is to move the reference population out of the load event (if possible). Then, in Load, do something like:
private bool _LoadComplete;
void OnFormLoad(Object sender, EventArgs e)
{
_LoadComplete = true;
InitializeControls();
_LoadComplete = false;
}
void InitializeControls()
{
// Populate Controls
}
void OnSomeControlEvent()
{
if (_LoadComplete)
{
// Handle the event
}
}
Edit a couple of other ideas:
- Set Application.Cursor = WaitCursor (usually disables clicking, but not 100% guaranteed).
- Create a spinner control to let the user know the screen is busy. When loading brings it in from the front, it sits on top and covers all the other controls. Once you're done loading, set it to visible = false and show your other controls.
source to share