我在窗口中创建了8个标签,名为
label1的,LABEL2,LABEL3,label4,label5,label6,label7,的Label8
如何使用循环处理某些标签?
这是VB.NET代码,我想将VB.NET转换为C#
For i=1 to 5
Me.Controls("label" & i).Visible = False
Next i
更新
for (int i = 1; i <= 5; i++)
{
Control[] lbl = this.Controls.Find("label" + i, true);
(lbl[0] as Label).Visible = false;
}
答案 0 :(得分:0)
表示i = 1到5 接下来我
等于
for(int i = 1; i&lt; = 5; i ++)
{}
然后,您尝试按名称
获取标签for(int i =1;i<=5;i++)
{
Label lbl= this.Controls.Find("label"+i, true).FirstOrDefault() as Label;
lbl.Visible= false;
}
答案 1 :(得分:0)
感谢回复
,我发现效果相同 private void Form1_Load(object sender, EventArgs e)
{
for (int i = 1; i <= 5; i++)
{
Control[] lbl = this.Controls.Find("label" + i, true);
(lbl[0] as Label).Visible = false;
}
}