FlowLayoutPanel - Automatic Width for controls?

MilMike picture MilMike · Mar 22, 2011 · Viewed 39.9k times · Source

is it possible to make the inserted items in FlowLayoutPanel automatic size of the FlowLayoutPanel? Here is an example:

A form with 1 FlowLayoutPanel and 3 buttons inside:

enter image description here

if I resize the form, the controls look like this: they arrange "left to right"

enter image description here

What I want is this: The controls should have the width of the FlowLayoutPanel:

enter image description here

Any Ideas how to do this? I changed the FlowDirection and played with the Anchor property but with no luck.

I could of course Resize the controls in the FlowLayoutPanel_Resize event, but I want to add about 500 usercontrols - I tested it and it is slow.

Answer

arbiter picture arbiter · Mar 22, 2011

I suggest you using TableLayoutPanel with one column in this case. I have found TableLayoutPanel much more predictable and solid than FlowLayoutPanel.

Another option, if you still want to use FlowLayoutPanel, is to set first control width to desired one, and use Dock = Top for all other controls.