FlowLayoutPanel AutoSize height not working

廉价感情. 提交于 2019-12-07 12:53:43

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/1971157/flowlayoutpanel-autosize-height-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!