我想在表单中使用多个标签。我使用以下代码:
Label[] lblLeftUp = new Label[12];
for (int i = 0; i < 12; i++)
{
lblLeftUp[i] = new Label();
lblLeftUp[i].Location = new Point((100 + (20 * i)), 100);
lblLeftUp[i].Text = Convert.ToString(i + 1);
this.Controls.Add(lblLeftUp[i]);
}
但是,我只能看到一个标签。有什么想法解决这个问题吗?
答案 0 :(得分:1)
标签互相阻挡。所以试试这个:
lblLeftUp[i].AutoSize = true;
答案 1 :(得分:0)
这是因为lblLeftUp[i].Location = new Point((100 + (20 * i)), 100);
。
如何看,你为以下标签设置了错误的位置。实际上 20 是不够的。所以我的建议是根据标签的大小设置dipending的位置。所以,如果你想要标签水平。试试这个:
Label[] lblLeftUp = new Label[12];
int PointX = 100; //100 is the initial distance from the left border of the control
for (int i = 0; i < 12; i++)
{
lblLeftUp[i] = new Label();
lblLeftUp[i].Location = new Point(PointX, 100);
lblLeftUp[i].Text = Convert.ToString(i + 1);
this.Controls.Add(lblLeftUp[i]);
PointX += lblLeftUp[i].Width;
}