【发布时间】:2009-05-15 09:32:52
【问题描述】:
在我的代码中,我需要遍历 GroupBox 中的控件,并且仅当它是 ComboBox 时才处理该控件。我正在使用代码:
foreach (System.Windows.Forms.Control grpbxChild in this.gpbx.Controls)
{
if (grpbxChild.GetType().Name.Trim() == "ComboBox")
{
// Process here
}
}
我的问题是:可以只从 GroupBox 中获取组合框,而不是循环遍历所有控件并仅处理组合框吗?像这样的:
foreach (System.Windows.Forms.Control grpbxChild in this.gpbx.Controls.GetControlsOfType(ComboBox))
{
// Process here
}
【问题讨论】: