private void OperateControls(Control control)
{
foreach(Control c in control.Controls)
{
if(c is Panel)
{
OperateControls(c);
}
if(c is GroupBox)
{
OperateControls(c);
}
if(c is TextBox)
{
// 它是 TextBox, 要干什么随便你
}
}
}
遍历tabcontrol控件的所有的tabpage中的所有控件
foreach (TabPage page in tabControl1.TabPages)
{
foreach (Control control in page.Controls)
{
if (control is TextBox)
{
((TextBox)control) = "";
}
if (control is ComboBox)
{
((ComboBox)control).SelectedIndex = -1;
}
}
}
//在父控件中查找子控件名称返回结果集
objec obj = Panel1.Controls.Find("控件名称",fale).First();
//将结果集中控件提取切转换类型
Label lab = obj as Label;
string labName = lab.Name;
string labText = lab.Text;
foreach (Control control in this.Controls)
{
if (control.Name == name)
{
Button button = (Button)control;
}
}