问题是,我们尝试使用“Width = Parent.Width”设置宽度.这可行,但是通过我们的方法,通过XML文件创建UI,在我们想要设置宽度的那一刻,GroupBoxes还没有父级.它将在稍后添加到FlowLayoutPanel中.
顺便说一下,我们还将“FlowDirection = TopDown”添加到FlowLayoutPanel,但是如果GroupBoxes变小,则将它们并排放置而不是TopDown.
因此,我们正在寻找一种方法来将所有控件置于彼此之下,并使所有GroupBox与FlowLayoutPanel具有相同的宽度.
感谢您的帮助,
多米尼克
注意:
对于FlowLayoutPanel的未来使用,您可能会发现这有用:
07000
This is the general rule for anchoring and docking in the FlowLayoutPanel control:
For vertical flow directions,the FlowLayoutPanel control calculates
the width of an implied column from the widest child control in the
column. All other controls in this column with Anchor or Dock
properties are aligned or stretched to fit this implied column. The
behavior works in a similar way for horizontal flow directions. The
FlowLayoutPanel control calculates the height of an implied row from
the tallest child control in the row,and all docked or anchored child
controls in this row are aligned or sized to fit the implied row.
例:
例如,如果您运行以下代码:
for (int i = 0; i < 5; i++) { var control = new GroupBox() { Text = i.ToString(),Dock = DockStyle.Top,Height = 40 }; this.panel1.Controls.Add(control); //To reverse the order,uncomment following line //control.BringToFront(); }
结果将是:
4 3 2 1 0
您可以通过取消注释注释代码来反转项目的顺序.