{
for (int j = 1; j <=8; j++)
{
Label l = new Label();
l.Text = i + "-" + j;
l.Width = 53;
l.Height = 20;
l.Location = new Point((j-1) * 60 + 53, (i-1) * 25 + 20);
l.Font = new Font(this.Font.FontFamily, 12);
l.TextAlign = ContentAlignment.MiddleCenter;
l.BackColor = Color.Yellow;
this.Controls.Add(l);
}
}
//给每个Lable添加Click事件
3 个解决方案
#1
l.Click+= 后按下Tab
for (int j = 1; j <=8; j++)
{
Label l = new Label();
l.Text = i + "-" + j;
l.Width = 53;
l.Height = 20;
l.Location = new Point((j-1) * 60 + 53, (i-1) * 25 + 20);
l.Font = new Font(this.Font.FontFamily, 12);
l.TextAlign = ContentAlignment.MiddleCenter;
l.BackColor = Color.Yellow;
l.Click+=
this.Controls.Add(l);
}
for (int j = 1; j <=8; j++)
{
Label l = new Label();
l.Text = i + "-" + j;
l.Width = 53;
l.Height = 20;
l.Location = new Point((j-1) * 60 + 53, (i-1) * 25 + 20);
l.Font = new Font(this.Font.FontFamily, 12);
l.TextAlign = ContentAlignment.MiddleCenter;
l.BackColor = Color.Yellow;
l.Click+=
this.Controls.Add(l);
}
#2
注册事件啊...
#3
非常感谢两位!
#1
l.Click+= 后按下Tab
for (int j = 1; j <=8; j++)
{
Label l = new Label();
l.Text = i + "-" + j;
l.Width = 53;
l.Height = 20;
l.Location = new Point((j-1) * 60 + 53, (i-1) * 25 + 20);
l.Font = new Font(this.Font.FontFamily, 12);
l.TextAlign = ContentAlignment.MiddleCenter;
l.BackColor = Color.Yellow;
l.Click+=
this.Controls.Add(l);
}
for (int j = 1; j <=8; j++)
{
Label l = new Label();
l.Text = i + "-" + j;
l.Width = 53;
l.Height = 20;
l.Location = new Point((j-1) * 60 + 53, (i-1) * 25 + 20);
l.Font = new Font(this.Font.FontFamily, 12);
l.TextAlign = ContentAlignment.MiddleCenter;
l.BackColor = Color.Yellow;
l.Click+=
this.Controls.Add(l);
}
#2
注册事件啊...
#3
非常感谢两位!