【发布时间】:2015-03-30 00:08:55
【问题描述】:
//这里我在运行时一键创建标签
Label[] labels = new Label[countresult];
for (int i = 1; i < countresult; i++)
{
labels[i] = new Label();
labels[i].Font = new Font("Arial Rounded MT Bold", 30);
labels[i].ForeColor = System.Drawing.Color.Red;
labels[i].AutoSize = true;
labels[i].Text = "";
//Here I try to assign the value visible = true
labels[i].Visible = true;
labels[i].TabIndex = i;
}
//在计时器滴答的私有空白中,我将标签的名称分配给 var "a" 并执行 3 个方法
string a = string.Format("labels[{0}]", labelscount);
//第一种方法
if (this.Controls.ContainsKey(a))
{
this.Controls[a].Visible=false;
}
//第二种方法
foreach (Control control in Controls)
{
if (control.Name == a)
{
control.Visible = false;
}
}
//第三种方法
if (this.Controls[a] is Label) this.Controls[a].Visible=false;
labelscount++;
不幸的是,没有任何工作。
有人知道发生了什么吗?
【问题讨论】:
-
标签[i].Visible = false;您是否尝试过专门调用它?
-
您是否真的将标签添加到父控件?
-
是的,我尝试了,但是说当前上下文中不存在该名称
标签: c# label visible invisible