How to get FlowLayoutPanel.AutoSize to work with FlowBreak

前端 未结 3 1081
忘掉有多难
忘掉有多难 2021-01-04 06:50

I have a problem with a FlowLayoutPanel and I don\'t know how to solve it.

I\'m placing two FlowLayoutPanels inside another; the second inner flp has 3 buttons insid

相关标签:
3条回答
  • 2021-01-04 07:20

    Not a solution, but a workaround. It looks like you are trying to simulate behavior of TableLayoutPanel by using flow breaks in FlowLayoutPanel. Did you try using TableLayoutPanel instead? According to your screenshots in the comments, it should work perfectly for your needs.

    0 讨论(0)
  • 2021-01-04 07:30

    It is a bug, it's been around for a very long time. The issue is that the layout engine for FlowLayoutPanel calculates the width of the first row wrong, including the width of the 2nd control, even though it got wrapped to the second row.

    The workaround is silly but effective, add a dummy Panel with a Width of 0 after the 1st control. If you are doing this with the designer then drop it first and drag it in the right place, to the right of the 1st control. Then set its Margin to (0, 0, 0, 0) and Size to (0, 0) in the Properties window.

    0 讨论(0)
  • 2021-01-04 07:38

    I don't believe the FlowLayoutPanel was designed to do what you're trying to do. A TableLayoutPanel would probably be better suited. Add a TableLayoutPanel with a single column, and add each button to a row.

    Edit: I found a hackish work around. After the first button, create a Panel with the size of 0,0 and the margin of 0,0. Make sure that FlowBreak is set to false.

    enter image description here

    Edit: You only need to create one panel, after the first button, not one for each.

    0 讨论(0)
提交回复
热议问题