Panel.Dock Fill ignoring other Panel.Dock setting

后端 未结 10 1002
我寻月下人不归
我寻月下人不归 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:21

    Another, potentially cleaner option is to use the TableLayout control. Set up one row of the desired height for your top dock, and another row to fill 100% for your bottom. Set both panels inside to Fill, and you're done.

    (TableLayout does take some getting used to, though.)

    0 讨论(0)
  • 2020-12-04 06:21

    Also may be a fast solution to take the "Filled" component and right click, cut and paste in the desired area.

    0 讨论(0)
  • 2020-12-04 06:23

    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.

    0 讨论(0)
  • 2020-12-04 06:25

    I know this is an old post but I discovered something useful. To adjust sibling control order programatically for dynamically created control(s), you can do something like:

    parentForm.Controls.SetChildIndex (myPanel, 0) 
    

    In my case, I did this to move a Dock/Fill panel to be the first control in my form so that it would not overlap with another docked control set to Dock/Top (a menu strip).

    0 讨论(0)
  • 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;
    
    0 讨论(0)
  • 2020-12-04 06:31

    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)
    
    0 讨论(0)
提交回复
热议问题