:
public static IEnumerable<TControl> GetChildControls(this Control control) where TControl : Control
{
var children = (control.Controls != null) ? control.Controls.OfType<TControl>() : Enumerable.Empty<TControl>();
return children.SelectMany(c => GetChildControls(c)).Concat(children);
}
:
foreach (TextBox tb in this.GetChildControls<TextBox>())
{
tb.Text = String.Empty;
}
- ( ), .
:
yourForm.Controls.OfType<TextBox>().ToList().ForEach(textBox => textBox.Clear());