c#中有groupbox控件情况下遍历textbox控件赋值求教

2024-11-20 04:32:39
推荐回答(2个)
回答1:

foreach(Control control in GroupBox.Controls)//GroupBox 改为groupbox控件名
{
if(control is TextBox)
{
(control as TextBox).Text = control .Name.Substring ("textBox".Length);
}
}

回答2:

foreach(Control gb in this.Controls)
{
if(gb is GroupBox)
{
foreach (Control ctl in gb.Controls)
{
if (ctl is TextBox && ctl.Name == name)
{
ctl.Text = i.ToString();
}
}
}