Winforms .NET: Docking problem with ToolStrip and StatusStrip

Today I created a C# Winform with a ToolStrip and a SplitContainer beneath it. I wanted the SplitContainer to fill all of the form’s area but should start just under the ToolStrip, just like what you see in a normal Windows Form. To cover all area on the form and resize the SplitContainer with Form resize action I set the Dock property to FILL and the ToolStrip’s Dock property to TOP. The result was a SplitContainer spanning the whole Form and a ToolStrip on top of it. No! I tried a couple of different Dock value combinations with these controls but every time the result was one of them hiding the other one. And if you don’t set the Dock property it won’t resize itself with the Form.  After a little research on the internet and trying with different options I figured it out. The solution was not with the Docking values combination, they were right at the very first instance. It is the “Z” order of your controls which matter. Either:

  • Right click on SplitContainer and select “Bring to Front”
  • Or call BringToFront() in the code

The ToolStrip has to be at the back but since its Dock is set to TOP it will always be shown. And since SplitContainer is now brought at the Front it can’t be hidden by the ToolStrip.

 

16 thoughts on “Winforms .NET: Docking problem with ToolStrip and StatusStrip

  1. I had a very similar problem- CrystalReportViewer control set to FILL covered by a criteria panel docked to TOP. Your solution worked like a champ! Thanks!

  2. Man, you’re genius! :) Thanks very much, I don’t find it logical, but it works!
    Who would thought of that…

  3. ZOMG I was tearing my hair out on this one. I had resorted to putting 3 panels on every form/tab, one for toolstrip, one for statusbar, and one for splitcontainer. Thanks!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s