这个代码可以用 原理就是递归遍历所有控件
我来改造下吧
返回所有子控件列表
public ListGetAllControls(Control control)
{
var list=new List();
foreach (Control con in control.Controls)
{
list.Add(con);
if (con.Controls.Count > 0)
{
list.AddRange(GetAllControls(con));
}
}
return list;
}
public void GetAllControls(Control control)
{
if (control is TextBox)
{
。。。。。。
}
else if (control is ComboBox)
{
。。。。。。
}
else if (control is TreeView)
{
。。。。。。
}
else if (control is RadioButton)
{
。。。。。。
}
else if (control is DateTimePicker)
{
。。。。。。
}
else
{
foreach (Control control1 in control.Controls)
{
GetAllControls(control1);
}
}
}