Thursday, August 7, 2008

Using Dock Fill on a Control when you have a Menu and/or Status Bar

I have long been frustrated in Visual Studio .NET when I try to use a control's Dock property set to Fill and also have a Menu or Status bar on the same form. The Docked control typically fills to the form and is not the right size (not accounting for the size of the Menu or Status bar).

It turns out that there is a very simple (but not very obvious) solution to this problem. Taken from Alex Fr's response to a comment on a similar problem:

"Actually, all you need to do is rightclick the panel and choose "bring to front", the dock layout logic handles each component in order so when it reaches your panel first it doesnt know it has other components that fill up other parts of the container with their docking settings. "

Just make sure the Docked control is in front of the menu and status bar and it works as you would expect.


EagleLakeWoodworking said...

Wow...that was so simple it's mind boggling. Your site was the first google hit on this topic, and I'm glad you had such an easy solution to a problem that was driving me nuts. Thanks!

Sea said...

oh god ... /o\
Thanks a thousand times!

AlCaponi said...

Your my saviour!

Larry Cosgrove said...

Wow! That did work. So simple and elegant!

Thanks a million!

Matthew Cochrane said...


Anonymous said...