首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

怎么获取动态添加的控件name

2011-12-21 
如何获取动态添加的控件name?private int i0private void button1_Click(object sender, EventArgs e){P

如何获取动态添加的控件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]);} 

热点排行