views:

63

answers:

1

I need to write a delegate for a multi-threaded program that will enable/disable a variety of controls. It seems logical that using one handler for all controls would be the best choice, but I'm not even sure this is possible in .net and if so how to implement.

+1  A: 
public void SetControlsEnabled(bool enabled)
{
    // Make sure we're in the correct thread
    if (InvokeRequired)
    {
        // If not, run the method on the UI thread
        Invoke(new MethodInvoker(() => SetControlsEnabled(enabled)));
        return;
    }

    // Put all control code here, e.g:
    // control1.Enabled = enabled;
    // control2.Enabled = enabled;

    // Alternatively, do a foreach(Control c in Controls) { ... }

}
nasufara
Nice. What I was really looking for was the base class "control". Thanks.
Gio