日期:2014-05-18  浏览次数:20731 次

如何获取动态添加的控件name?
private int i=0;
private void button1_Click(object sender, EventArgs e)
{
  PictureBox myPic = new PictureBox();
  myPic.Name = "pic" + i;
  this.Controls.Add(myPic);
}
在创建了N个PictureBox之后,我想获取第i=5的PictureBox的Name属性,怎么解决?

------解决方案--------------------
创建:
C# code
       
CheckBox[] name = new CheckBox[num];
for (int i = 0; i < num; i++)
{
     name[i] = new CheckBox();
     name[i].Text = fileName[i];
     name[i].Location = new Point(20, 10 + i * 25);
     name[i].Size = new Size(104, 16);
     name[i].Checked = false;
     pointStyleDlg.panel2.Controls.Add(name[i]);
}