int x = 0;
for(int i=0;i<19;i++)
{
Label lb=new Label();
lb.Location=new Point(x,524);
lb.Size= new Size(48,16);
lb.BorderStyle = BorderStyle.Fixed3D;
lb.Name = "Com"+i;
lb.Text = i + "关闭";
this.Controls.Add(lb);
x=x+48;
}
下面的代码中我如何试用他们?

解决方案 »

  1.   

    foreach (Control c in this.Controls)
    {    if (c is Label)
        {
           Label lb=c as Label;
           //接下来你想干嘛?    }
    }
      

  2.   

    private Label[] labels = new Label[19];
    private void Form1_Load(object sender, System.EventArgs e)
    {
                int x = 0;
                for(int i=0;i<19;i++)
                {
                    Label lb=new Label();
                    lb.Location=new Point(x,524);
                    lb.Size= new Size(48,16);
                    lb.BorderStyle = BorderStyle.Fixed3D;
                    lb.Name = "Com"+i;
                    lb.Text = i + "关闭";
                    this.Controls.Add(lb);
                    x=x+48;
                    this.labels[i] = lb;
                }
    }后面想随时访问labels都可以~
      

  3.   

    Eddie005(♂) №.零零伍 (︶︵︶) :他的方法不错!!!!!!!!
      

  4.   

    Eddie005(♂) №.零零伍 (︶︵︶) 谢谢你的好方法,原来这个叫控件数组,学习了,谢谢