继承面板不会自动调整大小
本文关键字:调整 继承 | 更新日期: 2023-09-27 18:04:25
首先,我的英语很差。如果有一些语法和书写错误,我很抱歉。
我的问题:
我们公司的许多程序都使用同一个DLL。在其中一个多用途dll中,我们创建了一些经常使用的基本UI对象。但是我们发现了一个bug,当DLL在特定程序中使用时:
我的团队通过WinForm创建了一个面板。通常情况下,它工作得很好:每当您启动面板时,窗体都会根据当前可用空间自动调整大小。为了实现这一点,我们使用了以下代码:
this.tableLayoutPanelMain.AutoSize = true;
this.tableLayoutPanelMain.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
目前没有问题。但是,在同一个程序中再次使用这个特定的面板后-我认为这个创建的面板在某种程度上是继承的-它不再自动调整大小了。相反,它得到了预定义的大小:
this.tableLayoutPanelMain.Size = new System.Drawing.Size(341, 69);
我不知道,为什么面板不再重新加载和自动调整大小。这里最大的问题是,我没有访问到特定的程序,这个错误发生和我们的DLL被使用。我只知道这里发生了错误。
我不是专业程序员。但我认为这与他们如何实施这个小组有关。我想,他们创造了一次,但再也不会了。所以只有一个面板,经常使用。但是,当这样做时,它不会刷新,也不再使用自动大小函数。
为了防止这个错误,我认为我必须实现这样的东西:不断刷新,无论何时使用,请自动调整大小。
但是我完全不知道。我从未使用过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();
我刚刚发现了问题所在:
如果通过调试模式启动(附加到进程),它会工作,但当作为发布启动时则不会。这看起来真的很奇怪。好像这个版本跳过了一些代码。