foreach (Control ctl in this.panel1.Controls) //遍历panel1中所有控件
{
if (ctl is Label)//挑选出是label类型的
{
if (ctl.Name == "lbl_" + ControlNameID) //判断控件名称
{
this.panel1.Controls.Remove(ctl); //移除
}
}
//if (ctl is TextBox)//挑选出是文本类型的
else
{
if (ctl.Name == "txt_" + ControlNameID) //判断控件名称
{
this.panel1.Controls.Remove(ctl); //移除
}
}
}
{
if (ctl is Label)//挑选出是label类型的
{
if (ctl.Name == "lbl_" + ControlNameID) //判断控件名称
{
this.panel1.Controls.Remove(ctl); //移除
}
}
//if (ctl is TextBox)//挑选出是文本类型的
else
{
if (ctl.Name == "txt_" + ControlNameID) //判断控件名称
{
this.panel1.Controls.Remove(ctl); //移除
}
}
}