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
2009-10-18 15:34:48
Nice. What I was really looking for was the base class "control". Thanks.
Gio
2009-10-22 05:15:22