读书人

为何不能显示全部的label控件

发布时间: 2012-09-19 13:43:53 作者: rapoo

为什么不能显示全部的label控件?
构造函数中的代码如下,运行之后为什么不能显示全部的label标签,只显示了一个,好像是第一个(位置为120,150的那一个)。
InitializeComponent();
ArrayList labelList=new ArrayList();
Label label=new Label();
label.Location = new Point(120, 150);
labelList.Add(label);
label.Location = new Point(138, 150);
labelList.Add(label);
label.Location = new Point(156, 150);
labelList.Add(label);
label.Location = new Point(174, 150);
labelList.Add(label);
label.Location = new Point(174, 132);
labelList.Add(label);
label.Location = new Point(174, 114);
labelList.Add(label);
label.Location = new Point(174, 96);
labelList.Add(label);
label.Location = new Point(156, 96);
labelList.Add(label);
label.Location = new Point(138, 96);
labelList.Add(label);
label.Location = new Point(120, 96);
labelList.Add(label);
label.Location = new Point(120, 114);
labelList.Add(label);
label.Location = new Point(120, 132);
labelList.Add(label);
for (int i = 0; i < labelList.Count;i++ )
{
Label lab=(Label)labelList[i];
lab.BackColor = Color.Blue;
lab.Size = new Size(16, 16);
lab.Text = "";
panel1.Controls.Add(lab);
}

[解决办法]
Label label=new Label();
label.Location = new Point(120, 150);
labelList.Add(label);
label=new Label();
label.Location = new Point(138, 150);
labelList.Add(label);
label=new Label();
label.Location = new Point(156, 150);
labelList.Add(label);
label=new Label();
label.Location = new Point(174, 150);
...

你一共只有一个label

读书人网 >C#

热点推荐