加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

xml – 将控件停靠在Docked FlowLayoutPanel中

发布时间:2020-12-16 07:58:00 所属栏目:百科 来源:网络整理
导读:我们将属性“Dock = Dockstyle.Fill”添加到我们的FlowLayoutPanel中,以便它调整大小并填充其父控件.现在我们向FlowLayoutPanel添加了两个GroupBox.这些应该与Panel具有相同的宽度,但是当我们使用“Dock = Dockstyle.Top”时它不起作用. 问题是,我们尝试使用
我们将属性“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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读