views:

147

answers:

1

I have a panel that renders a special header, this works all fine and good - but when I dock other controls inside of that panel, they size to fit underneath the header.

My thought was to try and catch this and control it somewhere. Getting the DisplayArea doesn't work - then the header doesn't draw in the right place. Is there any way I can tell docking to account for the height of the header?

Using C#, Windows Forms, .NET 3.5

Panel : System.Windows.Forms.UserControl Header : System.Windows.Forms.UserControl

Panel { Header { get; set; } }

is the basic structure. It's not terribly complicated.

+1  A: 

Controls are docked in order of their z-order, back to front. When you add a control at run-time it is generally added in back, which means it will be docked before preexisting controls, allowing the new control to sneak under existing controls. It does not matter what order the controls were docked in.

Try calling SendToBack on the header control after adding other controls (or if this is a design time issue, just right-click it and do "Send To Back").

Snarfblam
OP has not yet clarified whether this is run-time scenario. If run-time, the easiest way is just to call 'BringToFront on the control just after it's been added to the container, and its Dock property set.
BillW
I suppose so. Generally speaking it may be a better approach to bring a new control to front to yield to existing docked controls, rather than modifying those pre-existing controls to suit the new one. In this simple case the result is the same.
Snarfblam