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 titl
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.
!important
:).!important
)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