Search code examples
.netwinformsdocking

.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?


Solution

  • 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.