I have forms in my application that are variable length based on configuration in a database. These currently use TableLayoutPanels, and basically have a question followed by an answer like the below example:
There is logic to make fields invisible or visible based on the data in other fields. Currently it sets the height of a row to zero and makes the control invisible when it is not to display.
This causes issues with scrolling using a TableLayoutPanel (it doesn’t calculate height correctly and cuts fields off the page), so I am trying to change this to a FlowLayoutPanel, which seems more appropriate for this sort of thing anyway. However, this now causes the problem that invisible items take up space.
My problems are:
- Even when I set the height, width, padding and margin of controls in the FlowLayoutPanel to 0 as part of the invisible logic, they take up space in the FlowLayoutPanel
- Then when I try and set the Label control back to Autosize when an item is made visible again, it stays as width 0 and height 0 (the dropdowns/text entry fields on the other hand come back fine).
I have tried calling a Refresh() on controls after they are changed too and that doesn’t help either.
Is there a way I can achieve what I need with a FlowLayoutPanel or is there something else I should use?