开发者

.net docking controls

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

.net docking controls

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.

.net docking controls

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:

.net docking controls

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

.net docking controls

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?


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.


Set the DockStyle to Fill:

.net docking controls

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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜