Ladessa
Ladessa

Reputation: 1003

FlowLayoutPanel AutoSize only in vertical?

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

Answers (4)

help
help

Reputation: 95

Maybe

FlowLayoutPanel1.WrapContents = False;
FlowLayoutPanel1.FlowDirection = System.Windows.Forms.FlowDirection.TopDown;

will help you.

Upvotes: 4

undead10
undead10

Reputation: 1770

This might look like an ugly solution, but it works for me:

  1. Store current width of a panel in variable;
  2. Set AutoSize mode to true;
  3. Perform the action that require panel resize;
  4. 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

Nicolas Tyler
Nicolas Tyler

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

Ladessa
Ladessa

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

Related Questions