c#里如何实现控件数组

来源:互联网 发布:邮件群发软件 编辑:程序博客网 时间:2024/05/19 15:23

//建立4个Lable的控件数组,并赋值  
  private   void   creatBts()  
  {  
  System.Windows.Forms.Label[]   labArry   =new   System.Windows.Forms.Label[4];  
  for   (int   i=0;i<=3;i++)  
  {  
  labArry[i]   =   new   System.Windows.Forms.Label();  
  labArry[i].Location   =new   System.Drawing.Point   ((16+64*i),(16+24*i));  
  this.Controls.Add   (labArry[i]);  
  labArry[i].Text   =   i.ToString();  
  }  
  }   
  
 //Label[]   mylabel=new   Label[i];//i是label的数量-1  
  mylabel[0]=label1;  
  mylabel[1]=label2;  
  ....  
  for(int   j=0;j<=i;j++)  
  {  
    mylabel[j].Text="ok";  
  }

//for(int   i=0;i<10;i++)  
  {  
  ((TextBox)(this.FindControl("textBox"+i))).Text   =i;  
  }