自动调整面板上呈现的多个Windows窗体的大小 [英] auto-resize multiple windows forms being rendered on panel

查看:89
本文介绍了自动调整面板上呈现的多个Windows窗体的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有面板的Windows窗体。此表单包含三个面板。一个面板是可折叠的,并且充当侧边栏,另一个面板位于顶部,并在那里显示标题,最后一个是通过单击面板之一中要满足的项目之一来打开表单的占位符。 p>

现在我要做的是根据占位符的状态调整(扩大和缩小)占位符面板的大小(仅宽度)以及在面板上打开的窗体的大小。面板之一,可以展开或折叠。坞站无法正常工作。






如何停靠这些 Panels 来获得以下布局:



rong> Green Panel 位于表格的顶部。

DarkGray Panel 位于表格的左侧。

灰色面板占用了剩余空间。




  • 在Form容器中插入三个面板。

  • 绿色面板需要保持其位置,它永远不会改变:



    • 右键单击→SendToBack(!important :)。

    • Dock→顶部。


  • 暗灰色面板位于表单左侧绿色面板下方。它需要在需要时调整自身大小,但绝不会覆盖绿色面板:



    • Dock→Left


  • 灰色面板需要占用剩余空间。它需要在需要时调整自身大小,但是它永远不会覆盖绿色面板或深灰色面板:



    • 右键单击→BringToFront(!important

    • Dock→Center




对接时优先级最高的元素分配给堆栈中z顺序最低的元素:绿色面板,这里。
最低优先级分配给具有最高z顺序的元素:灰色面板,然后它将在所有其他具有较高优先级的元素中(紧随z顺序)收缩和拉伸



如何嵌入表格:



简单的部分。这是我们项目中的一个表格,重新父级时无需执行任何魔术操作即可保持生命:

(这仅适用于1个表格。使用更多表格,您将需要 List< Control>

  //在此定义表单将被嵌入
[您的表单类] EmbeddedForm;

私有void button1_Click(对象发送者,EventArgs e)
{
EmbeddedForm = new [您的表单类]( ){
TopLevel = false,
Parent = panContainer,
Location = new Point(4,4),
Enabled = true
};
EmbeddedForm .Show();
}

private void buttonShrink_Click(object sender,EventArgs e)
{
//可能会插入经典的点缀迷你按钮以重新
panelSideBar.Width = 6;
}

private void panelContainer_Resize(object sender,EventArgs e)
{
Rectangle rect = panelContainer.ClientRectangle;
rect.Inflate( -3,-3);
EmbeddedForm.Size = rect.Size;
}

如果您允许容器面板自动滚动它的内容,则不需要 Resize 事件。



编辑:

示例图形中Form的完整源代码的PasteBin:
嵌入式表格


I have this windows form with panels. This form has three panels. One panel is collapsible and acts as a sidebar, the other one sits at the top and is there for showing title, the last one is the placeholder for the forms being opened by clicking on one of the items being catered in panel one.

Now what I want to do is resize (grow and shrink) the size (width only) of the placeholder panel and the form that is opened on the panel according to the state of the panel one, which could either be expanded or collapsed. The dock is not working.

解决方案

After some clarifications, it appears that the desidered layout and behaviour of the described Form is similar to this sample disposition:

A WinForms Form is embedded in another Form, and placed inside a Panel.
This Guest Form is stripped of its TopLevel coat-of-arms and parented to central Panel, as shown in this graphic example:


How do you dock these Panels to get this layout:

The Green Panel stays on top of the Form.
The DarkGray Panel lays on the left hand side of the Form.
The Gray Panel occupies the remaining space.

  • Insert three Panels on a Form container.
  • The Green Panel needs to maintain its position, it will never change:
    • Right click → SendToBack (!important :).
    • Dock → Top.
  • The DarkGray Panel is positioned under the Green Panel, on the left side of the Form. It needs to resize itself when needed, but will never cover the Green Panel:
    • Dock → Left
  • The Gray Panel needs to occupy the remaining space. It needs to resize itself when needed, but it will never cover Green Panel or Dark Gray Panel:
    • Right click → BringToFront (!important)
    • Dock → Center

The highest priority when docking, is assigned to the element which has the lowest z-order in the stack: the Green Panel, here. The lowest priority is assigned to element with the highest z-order: the Gray Panel, which will then shrink and stretch among all other elements with higher priority (following the z-order).

How to embed the Form:

The easy part. It's a Form in our Project, no need to perform any magic to keep it alive when re-parented:
(This is just for 1 Form. With more Forms, you'll need something like a List<Control>:

//Define here the Form which will be embedded
[Your Form Class] EmbeddedForm;

private void button1_Click(object sender, EventArgs e)
{
    EmbeddedForm = new [Your Form Class]() {
        TopLevel = false,
        Parent = panContainer,
        Location = new Point(4, 4),
        Enabled = true
    };
    EmbeddedForm.Show();
}

private void buttonShrink_Click(object sender, EventArgs e)
{
    //Maybe insert a classic dotted mini-button to re-inflate the sidebar when needed
    panelSideBar.Width = 6;
}

private void panelContainer_Resize(object sender, EventArgs e)
{
    Rectangle rect = panelContainer.ClientRectangle;
    rect.Inflate(-3, -3);
    EmbeddedForm.Size = rect.Size;
}

If you allow your Container Panel to AutoScroll its content, the Resize event is not necessary.

Edit:
A PasteBin of the complete source code of the Form in sample graphics: Embedded Forms

这篇关于自动调整面板上呈现的多个Windows窗体的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆