Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#桌面布局面板填充_C#_Size_Fill_Tablelayoutpanel - Fatal编程技术网

C#桌面布局面板填充

C#桌面布局面板填充,c#,size,fill,tablelayoutpanel,C#,Size,Fill,Tablelayoutpanel,在TableLayoutPanel中,默认情况下,行或列中的最后一个元素占用剩余空间。如何实现倒数第二个元素或任何其他元素占用尽可能多的空间,以及最后一个元素只占用所需空间的布局?这取决于其他行的设置方式。 假设所有其他行都是自动调整大小或固定大小,将倒数第二行的大小设置为100%即可。设计器生成的代码如下所示: this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tableLayoutP

在TableLayoutPanel中,默认情况下,行或列中的最后一个元素占用剩余空间。如何实现倒数第二个元素或任何其他元素占用尽可能多的空间,以及最后一个元素只占用所需空间的布局?

这取决于其他行的设置方式。 假设所有其他行都是自动调整大小或固定大小,将倒数第二行的大小设置为100%即可。设计器生成的代码如下所示:

this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());

这取决于其他行的设置方式。 假设所有其他行都是自动调整大小或固定大小,将倒数第二行的大小设置为100%即可。设计器生成的代码如下所示:

this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());

我已经使用Windows窗体和.Net Framework 4对此进行了测试

最简单的解决方案似乎是创建一个表布局面板,并在每个列中嵌入控件。完成后,将所有列的大小设置为“自动调整大小”

然后将倒数第二列的大小设置为“100%”

以下是我的设计师的代码:

    tableLayoutPanel1 = new TableLayoutPanel();
    tableLayoutPanel1.ColumnCount = 4;
    tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
    tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
    tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
    tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());

请确保首先嵌入控件,因为如果其他单元格中没有内容,则将倒数第二列的大小设置为100%,然后使用设计器将控件放入空单元格会很困难,因为100%的列有效地“窃取”了它们的空间。

我已使用Windows窗体和.Net Framework 4测试了这一点

最简单的解决方案似乎是创建一个表布局面板,并在每个列中嵌入控件。完成后,将所有列的大小设置为“自动调整大小”

然后将倒数第二列的大小设置为“100%”

以下是我的设计师的代码:

    tableLayoutPanel1 = new TableLayoutPanel();
    tableLayoutPanel1.ColumnCount = 4;
    tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
    tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
    tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
    tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());

确保首先嵌入控件,因为如果其他单元格中没有内容,则将倒数第二列的大小设置为100%,这样就很难使用设计器将控件放入空单元格中,因为100%列有效地“窃取”了它们的空间。

多亏了你们,但dash是对的(Dominique是第一个) :P@DominiqueJacquel他是第一名。当我发布我的答案时,我被吓坏了,在那里看到了另一个非常相似的答案!感谢你们两位,但dash是对的(Dominique是第一个):P@DominiqueJacquel他是第一名。当我发布我的答案时,我被吓坏了,在那里看到了另一个非常相似的答案!