嵌套流程布局面板未换行
我有一个 FlowLayoutPanel,其属性为:
- Dock = Fill (在用户控件中)
- FlowDirection = TopDown
- WrapContents = false
我这样做,以便添加到面板的每个项目都添加到底部。
我添加到此面板的项目是用户控件,它们本身具有 FlowLayoutPanel,但它们具有标准行为(LeftToRight、WrapContents = true)。我遇到的问题是内部用户控件的 FlowLayoutPanel 没有调整大小以填充外部控件,但是当我在这些控件上将自动调整大小设置为 true 时,面板将不会包装其内容 - 这显然是一个已知问题。
如果它有助于形象化我正在尝试做的事情,它看起来像这样:
______________________________ | __________________________ | Outer box = exterior flowlayout | |Text____________________| | (TopDown, NoWrap) | | # # # # # # # # # # # #| | | | # # # # | | Interior boxes = usercontrols with text and a | |________________________| | flowlayoutpanel on them | __________________________ | (LeftToRight, Wrap) | |Text____________________| | | | # # # # # # # # # # # #| | # = pictures | | # # | | | |________________________| | |____________________________|
I've got a FlowLayoutPanel with properties:
- Dock = Fill (in a usercontrol)
- FlowDirection = TopDown
- WrapContents = false
I do it this way so that each item added to the panel gets added to the bottom.
The items that I add to this panel are usercontrols which themselves have FlowLayoutPanels on them, however they have the standard behaviour (LeftToRight, WrapContents = true). The problem that I'm having is that the interior usercontrol's FlowLayoutPanel isn't resizing to fill the outer control, but when I set autosizing to true on these controls, then the panel won't wrap its contents - which is a known problem apparently.
If it helps visualize what I'm trying to do, it looks like this:
______________________________ | __________________________ | Outer box = exterior flowlayout | |Text____________________| | (TopDown, NoWrap) | | # # # # # # # # # # # #| | | | # # # # | | Interior boxes = usercontrols with text and a | |________________________| | flowlayoutpanel on them | __________________________ | (LeftToRight, Wrap) | |Text____________________| | | | # # # # # # # # # # # #| | # = pictures | | # # | | | |________________________| | |____________________________|
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您不能将控件停靠在 FlowLayoutPanel 中,除非您继承 LayoutEngine 并使用自定义引擎创建您自己的窗格版本。然而,这个问题有一个很棒的解决方案。使用 TableLayoutPanel!由于您只需要 1 列,因此使用 TableLayoutPanel 来实现此目的非常容易。
唯一需要注意的是,TLP 最初需要有 0 行,然后以编程方式添加用户控件。诀窍是将用户控件停靠到顶部。这是有效的:
在本例中,UserControl1 是一个带有 FLP 的用户控件,其中有一堆按钮,因此我可以确认对接和流动是否有效。
I don't think you can dock controls in a FlowLayoutPanel, unless you subclass LayoutEngine and make your own version of the pane using your custom engine. However, there's an awesome solution to this problem. Use a TableLayoutPanel! Since you only want 1 column, it's very easy to use a TableLayoutPanel for this purpose.
The only caveat is that the TLP needs to have 0 rows initially, and you then add the user controls programmatically. And the trick is to dock the user control to Top. This works:
UserControl1 in this case was a user control with a FLP on it which had a bunch of buttons in it so I could confirm that the docking and flowing would work.