FlowLayoutPanel AutoSize 高度不起作用

发布于 2024-08-16 05:07:21 字数 992 浏览 9 评论 0原文

我正在开发一个 UserControl,它由一堆在 flowlayoutpanel 中的控件顶部水平排列的 ComboBox 和直接位于 flowlayoutpanel 下方的 datagridview 组成,该 datagridview 占据了控件上的所有剩余空间。我需要能够轻松隐藏所有下拉菜单,因此我有一个 Orientation == Horizo​​ntal 的 SplitContainer,其中 flowlayoutpanel 位于 SplitContainer.Panel1 中,datagridview 位于 SplitContainer.Panel2 中。

控件层次结构如下:

SplitContainer1
    SplitContainer1.Panel1
        FlowLayoutPanel1
            ComboBox1
            ComboBox2
            ComboBox3
    SplitContainer1.Panel2
        DataGridView1

由于 flowlayoutpanel 是水平方向且水平空间有限,因此 flowlayoutpanel 的 WrapContents 属性为 True,因此当控件太窄而无法容纳所有下拉菜单时,下拉菜单将向下换行到下一行排。

我遇到的问题是,当 flowlayoutpanel 将其内容包装到下一行时,其 Height 属性不会相应更改。 flowlayoutpanel 的包裹行会被剪裁,并且不会强制 splitcontainer 面板相应地增加高度。我尝试处理 FlowLayoutPanel.Resize 事件来增大和缩小 SPlitContainer.SplitterDistance 属性以容纳包装的内容,但 FlowLayoutPanel.Height 属性在内容包装时不会更改。我很困惑。 FlowLayoutPanel 是否损坏?如果 FlowLayoutPanel.Height 始终保持不变,无论内容如何换行,如何调整 FlowLayoutPanel 的父容器的大小?

谢谢

I'm working on a UserControl that consists of a bunch of ComboBoxes arranged horizontally across the top of the control in a flowlayoutpanel, and a datagridview directly below the flowlayoutpanel that takes up all remaining space on the control. I need to be able to hide all the dropdowns easily, so I have a SplitContainer with Orientation == Horizontal, with the flowlayoutpanel in SplitContainer.Panel1, and the datagridview in SplitContainer.Panel2.

The control hierarchy is as follows:

SplitContainer1
    SplitContainer1.Panel1
        FlowLayoutPanel1
            ComboBox1
            ComboBox2
            ComboBox3
    SplitContainer1.Panel2
        DataGridView1

Since the flowlayoutpanel is oriented horizontally and horizontal space is limited, the flowlayoutpanel's WrapContents property is True, so that the dropdowns wrap down to the next row when the control is made too narrow to fit all the dropdowns in one row.

The problem I'm having is that when the flowlayoutpanel wraps its contents down onto the next row, its Height property does not change accordingly. The wrapped rows of the flowlayoutpanel are clipped, and don't force the splitcontainer panel to grow in height accordingly. I've tried to handle the FlowLayoutPanel.Resize event to grow and shrink the SPlitContainer.SplitterDistance property to accommodate the wrapped contents, but the FlowLayoutPanel.Height property does not change when contents are wrapped. I'm stumped. Is the FlowLayoutPanel broken? How can I resize the FlowLayoutPanel's parent container if FlowLayoutPanel.Height always remains the same, regardless of content wrapping?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

昔梦 2024-08-23 05:07:21

看来你让这个对于你的需要来说有点太复杂了。您可以使用内置对接来完成您想要的任务,而无需使用 SplitContainer。像这样设置表单:

FlowLayoutPanel1 (Autosizse = true, Dock = Top)
  ComboBox1
  ComboBox2
  ComboBox3
DataGridView1 (Dock = Fill)

然后,当您想要隐藏 FlowLayoutPanel1 时,只需切换 Visible 属性即可隐藏/显示它。

It seems like you're making this a little too complicated for what you need. You can use the built-in docking to accomplish what you want without using the SplitContainer. Set up your form like this instead:

FlowLayoutPanel1 (Autosizse = true, Dock = Top)
  ComboBox1
  ComboBox2
  ComboBox3
DataGridView1 (Dock = Fill)

Then when you want to hide FlowLayoutPanel1 you can just toggle the Visible property to hide/show it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文