//建立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;
}
这篇博客介绍了如何在C#中创建和操作控件数组,特别是针对Label和TextBox控件。首先通过示例展示了如何初始化和设置Label控件数组的位置和文本,然后演示了如何为已存在的Label控件分配数组。此外,还提到了动态查找并设置TextBox控件文本的方法。
913

被折叠的 条评论
为什么被折叠?



