将c#中数组中的标签置于最前面
本文关键字:于最 标签 前面 数组 | 更新日期: 2023-09-27 18:21:21
我创建了一组标签,试图在一个有游戏板图片的图片框上显示。我一直在图片框后面显示标签,不确定自己做错了什么。
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
// 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循环