C# 如何让表格布局适合100%的容器

C# 如何让表格布局适合100%的容器,c#,tablelayoutpanel,C#,Tablelayoutpanel,如何将tablelayoutpanel的宽度设置为100%,以便它可以填充父容器,并在调整窗口大小时调整表的大小 我的表单现在如下所示: 我想动态添加行,因此结果如下: 如果这张桌子适合splitcontainer面板,那就太好了。有人知道怎么做吗 这是向表中添加行的当前代码: tableLayoutPanel1.CellBorderStyle = TableLayoutPanelCellBorderStyle.Outset; tableLayoutPanel1.GrowStyle = Ta

如何将tablelayoutpanel的宽度设置为100%,以便它可以填充父容器,并在调整窗口大小时调整表的大小

我的表单现在如下所示:

我想动态添加行,因此结果如下:

如果这张桌子适合splitcontainer面板,那就太好了。有人知道怎么做吗

这是向表中添加行的当前代码:

tableLayoutPanel1.CellBorderStyle = TableLayoutPanelCellBorderStyle.Outset;
tableLayoutPanel1.GrowStyle = TableLayoutPanelGrowStyle.AddRows;

tableLayoutPanel1.Controls.Add(new Label() { Text = "first row:", Anchor = AnchorStyles.Left, AutoSize = true });
tableLayoutPanel1.Controls.Add(new Label() { Text = "second row:", Anchor = AnchorStyles.Left, AutoSize = true });
tableLayoutPanel1.Controls.Add(new Label() { Text = "third row:", Anchor = AnchorStyles.Left, AutoSize = true });
tableLayoutPanel1.Controls.Add(new Label() { Text = "4th row:", Anchor = AnchorStyles.Left, AutoSize = true });
tableLayoutPanel1.Controls.Add(new Label() { Text = "5th row:", Anchor = AnchorStyles.Left, AutoSize = true });
tableLayoutPanel1.Controls.Add(new Label() { Text = "6th row:", Anchor = AnchorStyles.Left, AutoSize = true });
tableLayoutPanel1.Controls.Add(new Label() { Text = "7th row:", Anchor = AnchorStyles.Left, AutoSize = true });
我可以将列和行的宽度或高度设置为100%,那么如何将表的宽度或高度设置为100%

// 
// tableLayoutPanel1
// 
this.tableLayoutPanel1.ColumnCount = 1;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.tableLayoutPanel1.RowCount = 2;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel1.Size = new System.Drawing.Size(754, 169);
//this.tableLayoutPanel1.Size = new System.Drawing.Size(100F, 169);//pseudo code
this.tableLayoutPanel1.TabIndex = 0;

您需要将DockStyle设置为“填充”

您可以在设计器中使用
Dock
属性并从下拉列表中选择“填充”,或按代码执行此操作:

this.tableLayoutPanel1.Dock = DockStyle.Fill

啊,这比我想的容易。非常感谢。