【问题标题】:How to properly autoresize splitPanels and their elements如何正确自动调整拆分面板及其元素的大小
【发布时间】:2015-11-10 05:47:52
【问题描述】:

我的表单由一个 splitContainer 和两个水平面板、顶部面板上的几个按钮和底部面板上的图表组成。

当表单加载时,顶部面板被剪切并且一些元素被隐藏/剪切。此外,如果我调整表单大小,则元素或 splitContainer 都不会调整大小。

怎样才能正确做到呢?

我尝试使用 Form_Load() 中的 autoresize 属性

//this.AutoSize = true;
//this.AutoSizeMode = AutoSizeMode.GrowAndShrink;

这些是 splitContainer 属性

//
// splitContainer1
// 
this.splitContainer1.BackColor = System.Drawing.SystemColors.ControlDarkDark;
this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
this.splitContainer1.FixedPanel = System.Windows.Forms.FixedPanel.Panel1;
this.splitContainer1.Location = new System.Drawing.Point(0, 0);
this.splitContainer1.Name = "splitContainer1";
this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal;
// 
// splitContainer1.Panel1
// 
this.splitContainer1.Panel1.Controls.Add(this.btnPlay);
this.splitContainer1.Panel1.Controls.Add(this.grpOptions);
this.splitContainer1.Panel1.Controls.Add(this.grpDisplay);
this.splitContainer1.Panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.splitContainer1_Panel1_Paint);
// 
// splitContainer1.Panel2
// 
this.splitContainer1.Panel2.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
this.splitContainer1.Size = new System.Drawing.Size(784, 561);
this.splitContainer1.SplitterDistance = 69;
this.splitContainer1.TabIndex = 0;

这是截图:

【问题讨论】:

  • the top panel is cut and some of the elements are hidden/cut 那是因为您在 splitContainer 中设置了 FixedPanel :this.splitContainer1.FixedPanel = System.Windows.Forms.FixedPanel.Panel1; 删除此行
  • 我删除了,但我仍然有同样的行为。
  • Panel1 是否调整大小?如果none of the elements or splitContainer resize 的问题仍然存在,请包含他们的设计器代码。截图也不错
  • 我注意到我可以在加载表单时通过拖动光标来调整 Panel1 的大小。我不想要那个。添加了行为的屏幕截图。

标签: c# forms winforms


【解决方案1】:

我建议你将控件锚定在 splitcontainer 上

【讨论】:

    【解决方案2】:

    我建议在顶部面板上输入TableLayoutPanel 并将按钮放入单元格中。然后,您可以在TableLayoutPanel 中设置调整行和列的大小行为,百分比或绝对值。确保按钮的Dock 属性设置为Fill。这将确保控件的平滑和正确调整大小。您也可以为底部面板采用类似的方法。

    【讨论】:

    • 我将表单更改为:SplitContainer 带有一个顶部面板和底部面板,然后在每个面板内部都有一个 TableLayoutPanel。但是,顶部面板仍然被切割(与屏幕截图相同)。我该如何解决?
    猜你喜欢
    • 2016-11-08
    • 2012-10-23
    • 1970-01-01
    • 1970-01-01
    • 2013-02-19
    • 1970-01-01
    • 1970-01-01
    • 2012-02-21
    • 1970-01-01
    相关资源
    最近更新 更多