2 回答

TA貢獻1866條經(jīng)驗 獲得超5個贊
首先不要為 for 循環(huán)中的每次迭代創(chuàng)建一個新列表,而是在循環(huán)之外創(chuàng)建它。其次,您必須Label在列表中添加一個新實例,然后才能通過它的索引訪問它:
List<Label> underline = new List<Label>();
int left = 300;
int top = 275;
for (int i = 0; i < data.solution.Length; i++) //data is the object that contains the word that is the solution
{
underline.Add(new Label());
underline[i].Parent = this;
underline[i].Text = "_";
underline[i].Size = new Size(35, 35);
underline[i].Location = new Point(left, top);
left += 30;
underline[i].Font = new Font(new FontFamily("Microsoft Sans Serif"), 20, FontStyle.Bold);
}
- 2 回答
- 0 關(guān)注
- 129 瀏覽
添加回答
舉報