1

Possible Duplicate:
Panel.Dock Fill ignoring other Panel.Dock setting

It seems that when I place my panels in winforms I get unexpected results. If I have 3 panels and I dock them all to the top so that hopefully they are all 1 after the other, I instead get the last one docking to the VERY top of the application, not to the bottom of the last docked panel.

I guess I am confused about how the dock property in winforms panels work!? Every time I try to layout my application I get a headache because one panel wants to dock where I don't want it.

Community
  • 1
  • 1
Corey Blair
  • 469
  • 1
  • 7
  • 13

3 Answers3

6

Use the "document outline" view in Visual Studio to see the hierarchical structure of your form. You'll be able to ensure that all panels are at the same level, under the same parent, and you'll be able to reorder them to change the docking behavior/priorities.

Romain Verdier
  • 12,833
  • 7
  • 57
  • 77
1

I did a little more research and found this question on stackoverflow Once I opened that window and moved the panel up in the hierarchy it docked EXACTLY how I expected and wanted to. I knew there had to be some type of control hierarchy I could mess with.

Community
  • 1
  • 1
Corey Blair
  • 469
  • 1
  • 7
  • 13
0

Ypu should check this

and you can try do :

     public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();

                CreatePanels();
            }

            private void CreatePanels()
            {

//YOu should create panelGlobal on your winform and set DockStyle.Fill
                 panelGlobal.Controls.Add(CreatePanel("topPanel",DockStyle.Top,Color.Red));
                 panelGlobal.Controls.Add(CreatePanel("bottomPAnel", DockStyle.Bottom, Color.Gray));
                panelGlobal.Controls.Add(CreatePanel("fillPanel",DockStyle.Fill,Color.Snow));
            }

            private Panel CreatePanel(string panelName, DockStyle dockStyle,Color color)
            {
                return new Panel() { Name = panelName, Dock = dockStyle , BackColor=color};
            }
        }
Community
  • 1
  • 1
ígor
  • 1,144
  • 7
  • 16