[c#] Panel.Dock Fill ignoring other Panel.Dock setting
Right click on the panel with Dock=Fill and click 'Bring to Front'.
This makes this control be created last, which takes into account the Dock settings on other controls in the same container.
If you create a panel on a form and set it to Dock=Top and drop another panel and set its Dock=Fill, it may fill the entire form, ignoring the first panel. Changing the tab order does nothing.
I ran into the same issue. Mine was with adding new/custom controls below the menu strip during run time. The problem was the controls when docked, decided to dock from the top of the form and completely ignoring the menu strip entirely, very annoying if you ask me. As this had to be done dynamically with code and not during design mode this became extremely frustrating. The simplest way I found is to create a panel during design mode and dock below the menu strip. From there you can just add/remove the controls to the panel and you can dock it during run time. No need to mess with all your controls on your form that do not really need to change, too much work depending on what you really need to do.
object.dock = Fill Panel.Controls.Add(object)
I've had the same problem and I managed to solve it.
If you have a container with
DockStyle.Fill the others should also have DockStyle but Top or whatever you want.
The important thing is to add the control with
DockStyle.Fill first in Controls then the others.
ComboBox cb = new ComboBox(); cb.Dock = DockStyle.Top; GridView gv = new GridView(); gv.Dock = DockStyle.Fill; Controls.Add(gv); // this is okay Controls.Add(cb);
but if we put cb first
Controls.Add(cb); Controls.Add(gv); // gv will overlap the combo box.
Here is a trick that worked for me..
Place the Top item and dock it top.
Place a Splitter, and also dock it top, then set it disabled (unless you want to resize the top).
Then Place the Fill object and set Docking to Fill. The object will stay below the splitter.