2

我在我的用户控件中添加了一个 tableLayoutPanel。

It is not docked or anchored.
It has 4 columns and 4 rows.
The items within each cell are docked fully within each cell.

列的大小设置如下。

-Column 1 - Percent - 100%
-Column 2 - Absolute - 25
-Column 3 - Absolute - 35
-Column 4 - Absolute - 25

据我了解,绝对值应始终保持正确的大小,然后第 1 列应占用其余空间。

当我最初创建控件时,一切看起来都很好。生病回去编码我的程序的其他一些区域并不重要,并且在某些时候我会返回到我的 tableLayoutPanel 所在的设计器,并且第四列将比以前更大。所以我必须打开列和行样式编辑器并将列的大小更改回 25。

我怎样才能让这些设置保持不变?它快把我逼疯了!

此处要求的是我的设计器代码。

        // 
        // tableLayoutPanel1
        // 
        this.tableLayoutPanel1.Anchor = System.Windows.Forms.AnchorStyles.None;
        this.tableLayoutPanel1.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.OutsetDouble;
        this.tableLayoutPanel1.ColumnCount = 4;
        this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
        this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 25F));
        this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 35F));
        this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 25F));
        this.tableLayoutPanel1.Controls.Add(this.label8, 0, 0);
        this.tableLayoutPanel1.Controls.Add(this.btnStartingUp, 3, 3);
        this.tableLayoutPanel1.Controls.Add(this.txtOffset, 2, 3);
        this.tableLayoutPanel1.Controls.Add(this.btnDurationUp, 3, 2);
        this.tableLayoutPanel1.Controls.Add(this.label10, 0, 1);
        this.tableLayoutPanel1.Controls.Add(this.btnFrequencyUp, 3, 1);
        this.tableLayoutPanel1.Controls.Add(this.txtFrequency, 2, 1);
        this.tableLayoutPanel1.Controls.Add(this.btnPowerUp, 3, 0);
        this.tableLayoutPanel1.Controls.Add(this.label9, 0, 2);
        this.tableLayoutPanel1.Controls.Add(this.txtLaserPower, 2, 0);
        this.tableLayoutPanel1.Controls.Add(this.label7, 0, 3);
        this.tableLayoutPanel1.Controls.Add(this.btnPowerDown, 1, 0);
        this.tableLayoutPanel1.Controls.Add(this.btnFrequencyDown, 1, 1);
        this.tableLayoutPanel1.Controls.Add(this.btnDurationDown, 1, 2);
        this.tableLayoutPanel1.Controls.Add(this.btnOffsetDown, 1, 3);
        this.tableLayoutPanel1.Controls.Add(this.txtDuration, 2, 2);
        this.tableLayoutPanel1.Location = new System.Drawing.Point(61, 610);
        this.tableLayoutPanel1.Margin = new System.Windows.Forms.Padding(0);
        this.tableLayoutPanel1.MaximumSize = new System.Drawing.Size(208, 98);
        this.tableLayoutPanel1.Name = "tableLayoutPanel1";
        this.tableLayoutPanel1.RowCount = 4;
        this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 21F));
        this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 21F));
        this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 21F));
        this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 21F));
        this.tableLayoutPanel1.Size = new System.Drawing.Size(208, 98);
        this.tableLayoutPanel1.TabIndex = 168;
4

1 回答 1

2

不是 100% 确定,但是一旦我在 TableLayoutPanel 中放置标签,我就能够复制问题。

设置标签AutoSize=true后,似乎会导致列调整大小问题。

当我更改所有标签AutoSize=false时,问题消失了,列大小保持不变。

TextBox 也会产生干扰,因为它们具有 AutoSize 属性(在设计器中或代码中不可见)来控制控件的高度。设置文本框MultiLine=true没有帮助。

创建我自己的文本框,我专门设置了AutoSize=false固定的问题:

public class TextBoxEx : TextBox {
  public TextBoxEx() {
    this.AutoSize = false;
  }
}
于 2012-03-30T18:50:53.870 回答