62,046
社区成员
发帖
与我相关
我的任务
分享
public static Control IterateThroughControl(Control parent)
{
Control control = null;
foreach (Control c in parent.Controls)
{
if (c.GetType() == typeof(TextBox))
{
control = c;
return control;
}
if (c.HasControls()) // 判断该控件是否有下属控件。
{
control = IterateThroughControl(c); //递归,访问该控件的下属控件集。
if (c.GetType() == typeof(TextBox))
return control;
}
}
return control;
}
foreach (Control c in this.Form.Controls)
{
if (c.GetType().Name=="ContentPlaceHolder")
{
foreach (Control c1 in c.Controls)
{
if c1....
}
}
}