C# 为什么';这个标签矩阵显示是否正确?

C# 为什么';这个标签矩阵显示是否正确?,c#,winforms,visual-studio,C#,Winforms,Visual Studio,我试图在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;

我试图在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";
    }
}
rows=columns=20;
字母=新标签[行、列];
对于(int i=0;i

您忘了指定
Size
属性,因此标签只包含一个与其他标签重叠的默认大小(宽度较大)

// ...
letters[i, j].Size = new Size(20, 20);
// ...

您忘记指定
大小
属性,因此标签只包含一个与其他标签重叠的默认大小(带有大的
宽度

// ...
letters[i, j].Size = new Size(20, 20);
// ...

您是否尝试过使用调试器查看哪里出了问题..?请使用
TableLayoutPanel
,而不是尝试手动布局控件。另外,如果您想在网格布局中显示一些文本,则
DataGridView
也适合您。@MethodMan我现在有了,而且我和j没有任何问题。您是否尝试过使用调试器查看哪里出错了…?请使用
TableLayoutPanel
而不是尝试手动布局控件。另外,如果您想在网格布局中显示一些文本,则
DataGridView
非常适合您。@MethodMan我现在有了,我和j没有任何问题