AI智能
改变未来

c#批量给label赋值

int i = 1;foreach (Control c in this.panel1.Controls){if (c is Label){c.Text = \"ok\"+i.ToString();i++;}}

赋值的顺序是根据Form1.Designer.cs

this.panel1.Controls.Add(this.button1);//foreach赋值顺序this.panel1.Controls.Add(this.label1);this.panel1.Controls.Add(this.label2);this.panel1.Controls.Add(this.label3);this.panel1.Controls.Add(this.label4);this.panel1.Controls.Add(this.label5);this.panel1.Controls.Add(this.label6);this.panel1.Controls.Add(this.label7);this.panel1.Controls.Add(this.label8);


赞(0) 打赏
未经允许不得转载:爱站程序员基地 » c#批量给label赋值