本文介绍了如何将UserControl停靠在FlowLayoutPanel中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个FlowLayoutPanel和一个UserControl.

I have a FlowLayoutPanel and a UserControl.

我已经在FlowLayoutPanel中添加了多个用户控件,并且试图将它们停靠在顶部,因此,当我更改FlowLayoutPanel的大小时,用户控件的大小(宽度)也会相应地发生变化./p>

I've added multiple usercontrols into the FlowLayoutPanel, and I'm trying to dock them to the top, so when I change the size of the FlowLayoutPanel the size (width) of the usercontrols changes accordingly.

推荐答案

您不能将任何东西停放在FlowLayoutPanel中,它只会被忽略.

You cannot dock anything inside a FlowLayoutPanel, it's simply ignored.

查看在此处回答显然是由Microsoft团队发布的.

Check out the answer here apparently posted by the Microsoft team.

他们说:

    private void flowLayoutPanel1_Layout(object sender, LayoutEventArgs e)
    {
        flowLayoutPanel1.Controls[0].Dock = DockStyle.None;
        for (int i = 1; i < flowLayoutPanel1.Controls.Count; i++)
        {
            flowLayoutPanel1.Controls[i].Dock = DockStyle.Top;
        }
        flowLayoutPanel1.Controls[0].Width = flowLayoutPanel1.DisplayRectangle.Width - flowLayoutPanel1.Controls[0].Margin.Horizontal;

    }

关键是要使用Layout事件.

这个解决方案在某种程度上对我有用.您的UserControl必须关闭AutoSize/保持统一大小.

This solution worked for me up to a point. Your UserControls have to have AutoSize turned off / stay a uniform size.

在我的情况下,我希望打开AutoSize,以便允许UserControl在填充FlowLayoutPanel的宽度的同时垂直扩展/收缩.

In my case I wanted AutoSize turned on so as to allow the UserControl to expand/contract vertically while filling the width of the FlowLayoutPanel.

我必须找到其他解决方案.但是以上内容可能对您有帮助.

I had to find a different solution. But the above might help you in your case.

这篇关于如何将UserControl停靠在FlowLayoutPanel中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 16:12