我的应用程序中有一个包含子控件的GroupBox(如附图所示)。我想要通过简单的foreach循环枚举所有的文本框,以执行一些验证。
此文档大纲将给出这些控件的组织结构的公正想法。
foreach (Control control in grpBxTargetSensitivity.Controls)
{
if (control is FlowLayoutPanel && control.HasChildren)
{
foreach (Control ctrl in control.Controls)
{
if (ctrl is Panel && ctrl.HasChildren)
{
foreach (Control tbox in ctrl.Controls)
{
if (tbox is TextBox)
{
TextBox textbox = tbox as TextBox;
validData &= !string.IsNullOrWhiteSpace(textbox.Text);
}
}
}
}
}
}
我的问题是,是否有更好的方法(可能通过LINQ)来获取所有容器内部的文本框等控件而不是上述方法?