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

0


source to share


4 answers


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.

+4


source


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.
+2


source


Unfortunately, the only way I know is to have a class variable (named the same as _loading), and in each handler, do something like:

If (! _loading )
{
    ...
}

      

And in your boot code, install _loading = true;

after the download is complete.

+1


source


If you just want to disable user input, you can set the form property Enabled

to false.

This results in blocking user input of any form control without changing the appearance of the controls; this is the method used internally by the method ShowDialog

.

0


source







All Articles