views:

1041

answers:

4

Hi,

I have a dialog with loads of control in it. Each and evey control will be populated during the loading sequence and it might take a while for it to get completely filled. Mean while, I don't wanna allow the user to click on any of the controls. In other words, I wanna disable the control from receiving the events and I don't wanna disable the controls (as it might look odd).Also, I don't wanna subscribe and unsubscribe for the events regular intervals. Is there any way to stop the controls from listening to the events for a brief time ??

Sudarsan Srinivasan

+1  A: 

Unfortunately the only way i know of is to have a class variable (called something like _loading) and in each control handler do something like:

If (! _loading )
{
    ...
}

And in your loading code set _loading = true; once you have finished loading.

Pondidum
+1  A: 

The easiest way is to move the control 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 other Ideas:

  • Set the Application.Cursor = WaitCursor (typically will disallow clicking, but not a 100% guarantee)
  • Create a "Spinner" control to let the user know that the screen is busy. When loading bring it to the front so it sits on top and covers all other controls. Once you're done loading set it to visible = false and show your other controls
STW
Yeah. I too got the same solution. Here is what I did, 1. Placed a panel on top of all the other controls2. Made the panel transparent by overriding the ExStyle and CreateParams properties of the control3. Controlled the visibility of the panel during busy operationsThanks for the suggestions
A: 

If you just want to disable user input, then you can set the form's Enabled property to false.

This has the effect of blocking user input to any of the form's controls, without changing the appearance of the controls; it's the technique used internally by the ShowDialog method.

Tim Robinson
Unfortunately, mine is a user control. The entire dialog a user control which is hosted to a parent form
+3  A: 

The whole point of disabling controls is to communicate to the user that the control cannot be used at a particular time. This is a convention that users have learned and are used to, so I would advice to follow that. Not doing that may confuse the users.

The easiest way is to disable the container in which the controls are located in, rather than disabling each and every control. A better way (or at least the way that I prefer) is to have a method that will control the Visible and Enabled properties of controls based on which state the UI is in.

Fredrik Mörk