Reputation: 1003
I'm loading images dynamically inside a FlowLayoutPanel
. I need for this panel to auto-size but only vertically.
Is this possible, and if so, how do I go about achieving it?
Upvotes: 9
Views: 13309
Reputation: 95
Maybe
FlowLayoutPanel1.WrapContents = False;
FlowLayoutPanel1.FlowDirection = System.Windows.Forms.FlowDirection.TopDown;
will help you.
Upvotes: 4
Reputation: 1770
This might look like an ugly solution, but it works for me:
Restore previous panel's width from the variable.
int i = _panel1.Width;
_panel1.AutoSize = true;
_panel1.AutoSizeMode = AutoSizeMode.GrowOnly;
/*some action going on here*/
_panel1.AutoSize = false;
_panel1.Size = new Size(_panel1.Width, 80);
Upvotes: 0
Reputation: 10552
Simple, add a event of type control added:
private void flowLayoutPanel1_ControlAdded(object sender, ControlEventArgs e)
{
if (flowLayoutPanel1.Controls.Count % 10 == 0)
flowLayoutPanel1.SetFlowBreak(e.Control as Control, true);
}
set AutoSize = true
set flowdirection = LeftToRight
Upvotes: 15
Reputation: 1003
I did set the Size from panel dinamically. Example:
int newHeight= listImages.Count/10 * 100; flowLayoutPanel1.Size = new Size(1143, newHeight);
It works for me. Thx all
Upvotes: 1