我试图在Windows窗体中创建标签网格,但只显示其中一列:
rows = columns = 20;
letters = new Label[rows, columns];
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
{
letters[i, j] = new Label();
letters[i, j].Parent = this;
letters[i, j].Name = i + "_" + j;
letters[i, j].TextAlign = ContentAlignment.MiddleCenter;
letters[i, j].Location = new Point(20 + 20 * i, 20 + 20 * j);
letters[i, j].Visible = true;
letters[i, j].Text = "A";
}
}
答案 0 :(得分:2)
您忘记分配Size
属性,因此标签只包含与其他标签重叠的默认尺寸(大Width
)。
// ...
letters[i, j].Size = new Size(20, 20);
// ...