vulkanino
vulkanino

Reputation: 9124

.net docking controls

I have created a CustomControl to show information labels and that can be minimized/restored with an arrow button:

enter image description here

It should be docked to the top of a form.

Then in the same form usually I have a center panel with all the normal controls, here it is showm in yellow just to highlight it.

enter image description here

Finally I have a bottom panel containing all the commands/buttons available on the form. This is docked to the bottom.

The problem is that I don't know how to set the center panel to automatically consume the available space when I collapse the top panel. That is, there's no a "Center" Docking style.

If I dock the middle panel to the top, then when I collapse the top one I get:

enter image description here

If I anchor the middle panel to all the edges, I get:

enter image description here

If I dock the middle panel to fill the area, then it fills all the client area of the form, regardless the existence of the other panels.

Yes I could create an event in the top control to notify who is interested about the size change but.. It's an ugly solution because it's not automatic: in every form I'll have to listen to the event and resize the middle panel accordingly.

Is there an elegant solution to this problem?

Upvotes: 1

Views: 1026

Answers (3)

Sunil Kumar
Sunil Kumar

Reputation: 111

Using Split container will solve the problem. Drag a Panel and make the panel dock property to top (which has ur expander/collapse button). Now drag a split container and change the oreintation to horizontal.and change dockstyle to fill.

Now in the splitcontainer top panel drag ur custom control and add ur form controls to the bottom splitter panel. When you want to hide the hide ur custom control write the following logic in button click on top panel

private void btnExpandCollapseOptions_Click(object sender, EventArgs e)
    {
        if (splMainContainer.Panel1Collapsed)
        {
            splMainContainer.Panel1Collapsed = false;
            btnExpandCollapseOptions.Image = ImageResource.collapseMinus;
//changing image to collapse/expand from imageresource.resx file
        }
        else
        {
            splMainContainer.Panel1Collapsed = true;
            btnExpandCollapseOptions.Image = ImageResource.ExpandPuls;
        }

    }

the bottom contorl will occupy the total space when custom control collapses

Upvotes: 1

hawbsl
hawbsl

Reputation: 16003

Set the DockStyle to Fill:

enter image description here

Add this control after the other two. To ensure it comes after the other two, CTRL-X it, then CTRL-V it back in.

Upvotes: 2

CodingWithSpike
CodingWithSpike

Reputation: 43698

You do want DockStyle.Fill however if that middle control is going 'behind' the top and bottom docked controls, then you need to re-order the controls. Internall WinForms processes the items in the order they were added to the parent. In VisualStudio designer, right-click on your middle panel that is docked to Fill, and select "Bring to Front" or "Move to Back". I forget which one it is offhand, but one of them should fix your issue.

Upvotes: 2

Related Questions