Panel.Dock Fill ignoring other Panel.Dock setting

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

    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.

    Example:

    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.
    

提交回复
热议问题