WinForm:继承面板不会自动调整大小

时间:2016-08-29 09:39:26

标签: c# .net winforms

首先:我的英语非常糟糕。如果有一些语法和写作错误,我很抱歉。

我的问题:

我们公司在许多程序中使用相同的DLL。在这些多用途DLL中,我们创建了一些经常使用的基本UI对象。但是当在特定程序中使用DLL时,我们发现了一个错误:

我的团队通过WinForm创建了一个面板。 Normaly它的效果非常好:无论何时启动面板,表单都会根据当前的可用空间进行自动调整。为了实现这一点,我们使用了以下代码:

this.tableLayoutPanelMain.AutoSize = true;
            this.tableLayoutPanelMain.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;

到目前为止没有问题。但是,在SAME程序中再次使用此特定面板之后 - 我认为这个创建的面板以某种方式继承 - 它不会再自动调整。相反,它获得了预定义的大小:

this.tableLayoutPanelMain.Size = new System.Drawing.Size(341, 69);

我不知道,为什么面板不再重新加载并再次自动调整。这里最大的问题是,我没有访问特定程序,发生此错误并使用我们的DLL。我只知道这个错误在某种程度上出现了。

我不是专业程序员。但我认为他们如何实施专家组有一些事情要做。我认为,他们创造了一次,但再也没有。所以只有一个面板,经常使用。但是在这样做时,它不会刷新,也不会再使用自动调整功能。

为了防止这个错误,我相信我不得不实现类似的东西:不断刷新,无论何时使用,请自动调整大小。

但我绝对不知道absolutley。我从未使用过winforms,只是使用XAML。所以,如果有人能帮助我,我会非常感激。

代码:

    this.tableLayoutPanelMain.AutoSize = true;
    this.tableLayoutPanelMain.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
    this.tableLayoutPanelMain.ColumnCount = 3;
    this.tableLayoutPanelMain.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
    this.tableLayoutPanelMain.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 16F));
    this.tableLayoutPanelMain.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 218F));
    this.tableLayoutPanelMain.Controls.Add(this.panelPasswordRepetitionError, 1, 2);
    this.tableLayoutPanelMain.Controls.Add(this.txtRepetition, 2, 2);
    this.tableLayoutPanelMain.Controls.Add(this.lblPasswordRepetition, 0, 2);
    this.tableLayoutPanelMain.Controls.Add(this.panelPasswordError, 1, 0);
    this.tableLayoutPanelMain.Controls.Add(this.txtPassword, 2, 0);
    this.tableLayoutPanelMain.Controls.Add(this.panelDummy, 0, 1);
    this.tableLayoutPanelMain.Controls.Add(this.passwordQualityBox1, 2, 1);
    this.tableLayoutPanelMain.Dock = System.Windows.Forms.DockStyle.Fill;
    this.tableLayoutPanelMain.Location = new System.Drawing.Point(0, 0);
    this.tableLayoutPanelMain.Margin = new System.Windows.Forms.Padding(0);
    this.tableLayoutPanelMain.Name = "tableLayoutPanelMain";
    this.tableLayoutPanelMain.RowCount = 3;
    this.tableLayoutPanelMain.RowStyles.Add(new System.Windows.Forms.RowStyle());
    this.tableLayoutPanelMain.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
    this.tableLayoutPanelMain.RowStyles.Add(new System.Windows.Forms.RowStyle());
    this.tableLayoutPanelMain.Size = new System.Drawing.Size(341, 69);
    this.tableLayoutPanelMain.TabIndex = 0;

忘了这个:

// PDFPasswordView
// 
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoSize = true;
this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.AutoValidate = System.Windows.Forms.AutoValidate.EnableAllowFocusChange;
this.Controls.Add(this.tableLayoutPanelMain);
this.DoubleBuffered = true;
this.Margin = new System.Windows.Forms.Padding(0);
this.Name = "PDFPasswordView";
this.Size = new System.Drawing.Size(341, 69);
this.Validated += new System.EventHandler(this.OnPDFPasswordViewValidated);
this.tableLayoutPanelMain.ResumeLayout(false);
this.tableLayoutPanelMain.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.markerProvider)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();

1 个答案:

答案 0 :(得分:-1)

所以我刚刚发现问题所在:

如果通过调试模式(附加到进程)启动它,但在启动时不启动。这真的好像很奇怪。似乎发布版正在跳过某些代码。