首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

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

2012-09-19 
为什么不能显示全部的label控件?构造函数中的代码如下,运行之后为什么不能显示全部的label标签,只显示了一

为什么不能显示全部的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

热点排行