The simplest option may be to 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 a delegate to make it fairly generic:
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; });
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…