动态的给一组名字相似的控件赋值,这个问题好多人问过了,也是一个难点,今天我就把我以前费了好大功夫弄的一个小例子贴出来希望对大家有用啊。
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++;
}
}
}
}
本文介绍了一种在C#中动态为一组名字相似的控件赋值的方法。通过一个具体的示例,演示了如何使用循环和条件判断来实现这一功能。
&spm=1001.2101.3001.5002&articleId=4944563&d=1&t=3&u=5197811510c041378c1275c28811ed35)
1391

被折叠的 条评论
为什么被折叠?



