动态的给一组名字相似的控件赋值,这个问题好多人问过了,也是一个难点,今天我就把我以前费了好大功夫弄的一个小例子贴出来希望对大家有用啊。
int i = 1;
string[] str ={ "one", "two", "thrie" };
private void button1_Click(object sender, EventArgs e)
{
for (int j = 0; j < 3; j++)
{
foreach (Control ctemp in this.Controls)
{
if (ctemp.Name == "textBox" + i.ToString())
{
ctemp.Text = str[i - 1];
i++;
}
}
}
}
转载于:https://blog.51cto.com/shenymce/238916