[英]Bring to front labels in array in c#
我創建了一個標簽數組,試圖在帶有游戲板圖片的圖片框上顯示這些標簽。 我一直在圖片框后面顯示標簽,但不確定我做錯了什么。
public Form1()
{
InitializeComponent();
int x = 100;
int y = 0;
// create 361 labels, set their dimensions
for (int i = 0; i < 361; i++)
{
board[i] = new Label();
board[i].Parent = pictureBox1;
board[i].Location = new Point(x, y);
board[i].Name = "label" + i;
board[i].Width = 55;
board[i].Height = 55;
board[i].Text = "0";
board[i].BackColor = Color.Black;
board[i].BringToFront();
}
// set the position of the label
foreach (Label i in board)
{
if (x >= 580)
{
x = 0;
y = y + i.Height + 55;
}
i.Location = new Point(x, y);
this.Controls.Add(i);
x += i.Width;
}
將標簽添加到表單容器后,將調用移至BringToFront
AFTER
// set the position of the label
foreach (Label i in board)
{
if (x >= 580)
{
x = 0;
y = y + i.Height + 55;
}
i.Location = new Point(x, y);
this.Controls.Add(i);
i.BringToFront();
x += i.Width;
}
順便說一下,這不是什么大的收獲,但是您可以將這段代碼放在第一個循環中並刪除foreach循環
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.