xml – 将控件停靠在Docked FlowLayoutPanel中

前端之家收集整理的这篇文章主要介绍了xml – 将控件停靠在Docked FlowLayoutPanel中前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我们将属性“Dock = Dockstyle.Fill”添加到我们的FlowLayoutPanel中,以便它调整大小并填充其父控件.现在我们向FlowLayoutPanel添加了两个GroupBox.这些应该与Panel具有相同的宽度,但是当我们使用“Dock = Dockstyle.Top”时它不起作用.

问题是,我们尝试使用“Width = Parent.Width”设置宽度.这可行,但是通过我们的方法,通过XML文件创建UI,在我们想要设置宽度的那一刻,GroupBoxes还没有父级.它将在稍后添加到FlowLayoutPanel中.

顺便说一下,我们还将“FlowDirection = TopDown”添加到FlowLayoutPanel,但是如果GroupBoxes变小,则将它们并排放置而不是TopDown.

因此,我们正在寻找一种方法来将所有控件置于彼此之下,并使所有GroupBox与FlowLayoutPanel具有相同的宽度.

感谢您的帮助,

多米尼克

在您描述的情况下,当您只需要自上而下的流程时,您可以简单地使用Panel而不是FlowLayoutPanel.将面板AutoScroll设置为true,将Dock设置为Fill,然后将组框添加到面板并将它们的Dock属性设置为Top.

注意:
对于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

您可以通过取消注释注释代码来反转项目的顺序.

原文链接:https://www.f2er.com/xml/293055.html

猜你在找的XML相关文章