TableLayoutPanel 大小调整不起作用 (C#)

TableLayoutPanel sizing doesn't work (C#)

我的 Windows 表单应用程序中有以下代码:

x = Convert.ToInt32(textBox1.Text);

tableLayoutPanel1.RowCount = x;
tableLayoutPanel1.ColumnCount = x;

我有一个文本框,用于确定 table 布局面板的行数和列数。问题是,单元格看起来像这样:

the picture

如何使单元格的大小相同?

您是否尝试过使用 RowStylesColumnStyles 属性?

TableLayoutRowStyleCollection styles =
tableLayoutPanel1.RowStyles;

foreach (RowStyle style in styles){
   // Set the row height to 20 pixels.
   style.SizeType = SizeType.Absolute;
   style.Height = 20;
}

还有:

TableLayoutColumnStyleCollection styles =
tableLayoutPanel1.ColumnStyles;

foreach (ColumnStyle style in styles){
   // Set the column width to 20 pixels.
   style.SizeType = SizeType.Absolute;
   style.Width = 20;
}

如果需要,您可以只使用 RowStyles 添加行的 width