problem with dock fill

I am using Visual Studio 2005 Professional Edition Version 8.0.50727.42. In a PocketPC2003 project, I am having trouble seting up one of my forms. The first thing I did is create a panel and dock it to the top. Then I created a label and a few check boxes and put them inside the panel. I docked the label to the top of the panel. below the first panel I have a splitter, also with its' dock property set to top. This positions it just below the first panel. Then, below the splitter, I have another panel with its' dock property set to fill. This causes it to fill up the remaing portion of the form. So far everything is working fine. Then inside the second panel, I placed a label and docked it to the top of that panel. Also inside the second panel I have a tree view docked to fill the rest of the panel, but this does not work how it should. Instead of filling the remaining portion of the panel(the part not occupied by the label), it fills the whole panel, with the lable covering up the top of it. I checked the Designer.cs for that form to see if everything was set how it should be, and it was. Is this a bug or am I doing something wrong Any help will be appreciated.


Answer this question

problem with dock fill

  • vchu

    if you get into that situation again, you can experiment around with right clicking on your controls in the designer and playing around with "send to back" and "bring to front". In reproducing what you saw, sending the checkbox to the back (or bringing the treeview to the front) would have made the docking work the way you expected it to.

  • Scottzrn

    To do the equivalent manually in code, use the Controls.SetChildIndex() function. Docked components fill backwards from their expected behavior: the most recently added child component will be docked closest to the container's outer edge, with the "older", lower index docked components toward the center of the container.

    Therefore, to add a component on the "inside" of the container, with the older, docked component toward the outside, you need to add the newer component at the front of the Controls set, instead of at the end. Unfortunately, there is no Controls.Insert() function; only a Controls.Add().

    Therefore, to add a new panel and dock it fill with other panels already docked, do this:

    Controls.Add(panel);
    Controls.SetChildIndex(panel,0);
    panel.DockStyle=DockStyle.Fill.


  • Mike Rorke - MSFT

    When I don't want do this in code, I don't have the possibility of playing around in the designer.
    Somehow it seems that in one of the applications I made, the order in which I put the controls in the form has great effect.

    On a form with a left panel, a splitter and a right (fill) panel, I have to add the fill first or it will capture the entire area (as described in the first post). I must add the splitter before the left panel, or otherwise it will end up on the left of the left panel.

    On the left form, there's a top panel, a bottom panel and a (fill) listview. I have to add the listview first, or it will, again, capture the whole client area of the parent panel. The other two don't influence each other's position, so I can add them in any order I want.

    This behaviour seems a bit picky though..

  • B-M-C

    yes, you are correct, the order of controls makes all the difference in docking/anchoring. The designer changes that order via SendToBack and BringToFront. If you don't have the luxury of using the designer you'll need to do the equivalent manually in code.

    That said, our docs can probably use some brushing up on this point. I will be forwarding this thread to our doc writer.



  • Andrew K Lee

    I still don't know if that was a bug or not, but I found a workaround. instead of having two panels and a splitter between them, I have one panel docked to the top with the same stuff inside it as mentioned before. Then I have a splitter also docked to the top. Then I have a label below that, also docked to top, but now it's not inside a panel. below that I have the tree docked to fill, and for some reason it works properly like this.

  • Artie Sluka

    You can modify the order that the controls are added in the [form name].Designer.cs file without having to re-add your controls. Search in this file for the section that contains the code "this.Controls.Add". Eg:

    this.Controls.Add(this.dgResults);
    this.Controls.Add(this.tbrMain);
    this.Controls.Add(this.spltHorizontal);
    this.Controls.Add(this.txtOutput);




  • problem with dock fill