我試圖用一致的間距對齊一定數量的標籤。 for循環之後的對齊很好,但爲什麼第一個間距與其他間距不一致呢?標籤之間的一致間距c#
private void FrmMainGame_Load(object sender, EventArgs e)
{
Label l = new Label();
int margin = 1;
int width = (this.ClientSize.Width + margin - l.Size.Width) /10 ;
l.BackColor = Color.Red;
l.BorderStyle = BorderStyle.FixedSingle;
int x = width + margin;
l.Location = new Point(0, 5);
l.Size = new Size(width, 20);
this.Controls.Add(l);
for (int i = 1; i <= 9; i++)
{
l = new Label();
l.BackColor = Color.Red;
l.BorderStyle = BorderStyle.FixedSingle;
x += margin + width;
l.Location = new Point(x,5);
l.Size = new Size(width, 20);
this.Controls.Add(l);
}
}
這是winforms嗎? WPF? – ryanyuyu