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:
if I resize the form, the controls look like this: they arrange "left to right"
What I want is this: The controls should have the width of the FlowLayoutPanel:
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.
There is no need for a
FlowLayoutPanel
here.You should be able to do what you want with a normal
Panel
control. Anchor it at all four sides so that it stretches with your form, then add your buttons and set them all to Dock: Top.Job Done.
here I have my StackPanel class:
The
FlowLayoutPanel
arranges controls in a particular way, according to MSDN:Its not ideal, but you can do this natively, as long as one child control is set to the same width as the container, and the rest of the controls are set to
Dock
.It's simple way to do this. Just bind the SizeChanged evnent of you flowLayoutPannel and resize the containing control. Like:
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.
I Suggest... try playing with the anchors of the buttons... try setting it as
or set it in the properties...
and then put it inside a Panel instead of the FlowLayoutPanel... ;)