for (int i = 0; i <20; i++)
{
Button btnNo = new Button();
btnNo.Name = i;
btnNo.Text="TEST"+i;
}
private void btnChange_Click(object sender, EventArgs e)
{
}
透过另外BUTTON,寻找button.Name=1,更改文本内容
------解决思路----------------------
大概方式类似这样:
for (int i = 0; i <20; i++)
{
Button btnNo = new Button();
btnNo.Name = i;
btnNo.Text="TEST"+i;
this.controls.Add(btnNo);//将btn添加到容器
}
private void btnChange_Click(object sender, EventArgs e)
{
foreach(Control ctr in this.Controls)
{
if(ctr is typeof(Button) && ctr.Name=="1")
{
Button btn = ctr as button//改变文本内容
btn.Name="......";
}
}