若要递归获取所有指定类型的控件和子控件,请使用以下扩展方法:
public static IEnumerable<TControl> GetChildControls<TControl>(this Control control) where TControl : Control
{
var children = (control.Controls != null) ? control.Controls.OfType<TControl>() : Enumerable.Empty<TControl>();
return children.SelectMany(c => GetChildControls<TControl>(c)).Concat(children);
}
用法:
var allText@R_35_2419@es = this.GetChildControls<Text@R_35_2419@>();
foreach (Text@R_35_2419@ tb in allText@R_35_2419@es)
{
tb.Text = ...;
}