Reputation: 4435
I have a FlowLayoutPanel with some buttons inside. I want the FlowLayoutPanel width to be the same as the biggest button, but the height to be fixed. How can I accomplish that? I have googled it but all I found was about WPF.
Upvotes: 2
Views: 2713
Reputation: 251
You should be able to achieve this by setting the anchors on your controls accordingly.
Upvotes: 3
Reputation: 81610
You can simply LINQ through the controls and find the maximum width of your buttons:
int maxWidth = flp.Controls.OfType<Button>().Max(x => x.Width) +
(flp.Margin.Left + flp.Margin.Right);
flp.ClientSize = new Size(maxWidth, flp.ClientSize.Height);
Upvotes: 1