.net docking controls
I have created a CustomControl to show information labels and that can be minimized/restored with an arrow button:
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.
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:
If I anchor the middle panel to all the edges, I get:
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:
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
精彩评论