FlowLayoutPanel AutoSize 高度不起作用
我正在开发一个 UserControl,它由一堆在 flowlayoutpanel 中的控件顶部水平排列的 ComboBox 和直接位于 flowlayoutpanel 下方的 datagridview 组成,该 datagridview 占据了控件上的所有剩余空间。我需要能够轻松隐藏所有下拉菜单,因此我有一个 Orientation == Horizontal 的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来你让这个对于你的需要来说有点太复杂了。您可以使用内置对接来完成您想要的任务,而无需使用
SplitContainer
。像这样设置表单:然后,当您想要隐藏
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:Then when you want to hide
FlowLayoutPanel1
you can just toggle theVisible
property to hide/show it.