【发布时间】:2011-06-27 14:51:12
【问题描述】:
我想根据数组创建标签,但我总是只得到一个标签。
private void button1_Click(object sender, EventArgs e)
{
Debug.WriteLine(hardrive.GetHardDriveName.Count);
Label[] lblHDDName = new Label[hardrive.GetHardDriveName.Count];
for (int i = 0; i < hardrive.GetHardDriveName.Count; i++)
{
int x = 10;
int y = 10;
lblHDDName[i] = new Label();
lblHDDName[i].Location = new System.Drawing.Point(x, y);
lblHDDName[i].Text = "Test";
groupBoxHDD.Controls.Add(lblHDDName[i]);
y += 10;
}
}
调试
Debug.WriteLine(hardrive.GetHardDriveName.Count);
显示数组中的两项。
问题是在 GroupBox 中只有一个标签而不是两个。
【问题讨论】: