The simplest option could be a cascade:
public static void SetEnabled(Control control, bool enabled) {
control.Enabled = enabled;
foreach(Control child in control.Controls) {
SetEnabled(child, enabled);
}
}
or similar; you could, of course, pass the delegate to make it pretty general:
public static void ApplyAll(Control control, Action<Control> action) {
action(control);
foreach(Control child in control.Controls) {
ApplyAll(child, action);
}
}
then things like:
ApplyAll(this, c => c.Validate());
ApplyAll(this, c => {c.Enabled = false; });
source
share