表布局面板-C#表单应用中的锚定

表布局面板-C#表单应用中的锚定,c#,winforms,C#,Winforms,我的c#表单应用程序中有两个表格布局面板。我通过设计工具(TableLayoutPanel1)创建了一个。第二个是动态创建的(TableLayoutPanel2)。第一个表布局实际上包含第二个表的标题。所以我想正确地对齐它们 我将TableLayoutPanel1的所有相同属性应用于TableLayoutPanel2。但它们仍然不一致。TableLayoutPanel2仅覆盖屏幕的一半,但TableLayoutPanel1覆盖整个屏幕 TableLayoutPanel TableLayoutPa

我的c#表单应用程序中有两个表格布局面板。我通过设计工具(TableLayoutPanel1)创建了一个。第二个是动态创建的(TableLayoutPanel2)。第一个表布局实际上包含第二个表的标题。所以我想正确地对齐它们

我将TableLayoutPanel1的所有相同属性应用于TableLayoutPanel2。但它们仍然不一致。TableLayoutPanel2仅覆盖屏幕的一半,但TableLayoutPanel1覆盖整个屏幕

TableLayoutPanel TableLayoutPanel2 = new TableLayoutPanel();
TableLayoutPanel2 .Size = new Size (1173,35);  //same size as 1
TableLayoutPanel2 .Anchor = AnchorStyles.Left | AnchorStyles.Right;  //left and right anchor

TableLayoutPanel2 .Location = new Point(5, 60);
TableLayoutPanel2 .RowCount = 1;
TableLayoutPanel2 .ColumnCount = 2;
TableLayoutPanel2 .ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
TableLayoutPanel2 .ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));


这里有什么问题?任何建议。

您在何处/何时创建此新TLP?您是否尝试过设置
TableLayoutPanel2.Size=tableLayoutPanel1.Size?你的应用程序是DpiAware吗?Yu还可以将它们添加到FlowLayoutPanel,并将它们锚定在这个外部容器中。另外,在代码中创建TLP时,请在添加自己的样式之前清除现有样式;这起作用了。谢谢