我想創建基於數組的標籤,但我總是隻能獲得一個標籤。C#從數組創建標籤
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中只有一個標籤而不是兩個。
好的,謝謝,多麼愚蠢的錯誤 – Chuck 2011-02-15 13:42:24