Panel.Dock Fill ignoring other Panel.Dock setting

后端 未结 10 1095
我寻月下人不归
我寻月下人不归 2020-12-04 06:02

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

10条回答
  •  醉话见心
    2020-12-04 06:29

    If you don't want to change the order of the elements inside the code, you can use the method Container.Controls.SetChildIndex() with Container being the e.g. Form, Panel etc. you want do add your controls to.

    Example:

         //Container ------------------------------------
         Panel Container = new Panel();
    
         //Top-Docked Element ---------------------------
         ButtonArea = new FlowLayoutPanel();
         Container.Controls.Add(ButtonArea);
         Container.Controls.SetChildIndex(ButtonArea, 1);
         ButtonArea.Dock = DockStyle.Top;
    
         //Fill-Docked Element --------------------------
         box = new RichTextBox();
         Container.Controls.Add(box);
         Container.Controls.SetChildIndex(box, 0); //setting this to 0 does the trick
         box.Dock = DockStyle.Fill;
    

提交回复
热议问题