Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.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# WinForm:继承的面板不会自动调整大小_C#_.net_Winforms - Fatal编程技术网

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

C# WinForm:继承的面板不会自动调整大小,c#,.net,winforms,C#,.net,Winforms,首先:我的英语很差。如果有语法和写作错误,我很抱歉 我的问题: 我们公司在很多程序中使用相同的DLL。在这些多用DLL的基础上,我们创建了一些常用的基本UI对象。但当DLL用于特定程序时,我们发现了一个错误: 我的团队通过WinForm创建了一个面板。正常情况下,它工作得很好:无论何时启动面板,窗体都会根据其当前可用空间自动调整大小。为了实现这一点,我们使用了以下代码: this.tableLayoutPanelMain.AutoSize = true; this.tab

首先:我的英语很差。如果有语法和写作错误,我很抱歉

我的问题:

我们公司在很多程序中使用相同的DLL。在这些多用DLL的基础上,我们创建了一些常用的基本UI对象。但当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();

所以我才发现问题出在哪里:


如果通过调试模式(附加到进程)启动,则它可以工作,但在作为发布启动时则不能工作。这看起来真的很奇怪。似乎该版本跳过了一些代码。

我猜它适合父级,因为这行:
this.tableLayoutPanelMain.Dock=System.Windows.Forms.DockStyle.Fill
无论如何,如果它在不同的程序中正常工作,最好在有错误的程序中修复它,我希望我能在图书馆工作,但这家公司非常分散。他们不可能允许我访问这些程序的源代码。玩他们的源代码根本不关我的事。我不得不接受这一点。所以我们必须自己解决这个问题。因为修复它是我的任务,所以我必须去做。我完全不知道如何去做。我不明白为什么你要负责修复你甚至看不见的代码,但我担心我们也不能出于同样的原因帮助你。您向我们展示的零件看起来不错,您提供的信息不足以找出此问题的原因。我祝你在这项任务中好运。这没有多大意义。如果基础控件具有所需的属性值,但派生控件未按预期工作,则这是因为派生控件替代了基础面板属性。显然,必须在问题所在的位置修复错误。如果您试图通过一些黑客行为在基本控件中修复它,那么您可能会在其他需要不同行为的地方破坏其他东西。如果问题出现在其他公司代码中,则由他们来解决。顺便说一句,你不应该解决一个你不理解的问题,因为你可能会弄坏更多的东西。这没有多大意义。要么是错误的代码(比如不正确地使用了
Debug.Assert
),要么是在某些情况下未正确构建应用程序。所以你可以试着重建allI我试着重建项目,但仍然没有成功。Debug.Assert也没有用。我完全不知道…唯一有效的方法是当我手动设置大小时,但我不想这样做,因为表单将不再灵活。