0

I'm trying to dynamically generate 2 FlowLayoutPanels with a couple of buttons.

    private void DrawButtons() {
        tlpButtons.Controls.Clear();

        foreach (var type in Globals.ThisAddIn.TicketTypes.OrderBy(x => x.Name)) {
            tlpButtons.Controls.Add(new Label() { Text = type.Name, Dock = DockStyle.Fill });
            var container = new FlowLayoutPanel() { Dock = DockStyle.Fill, AutoSize = true, AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowOnly, BackColor = Color.Yellow, FlowDirection = FlowDirection.LeftToRight };
            foreach (var skill in Globals.ThisAddIn.Skills.OrderBy(x => x.Name)) {
                container.Controls.Add(new Button() { Text = skill.Name });
                MessageBox.Show(tlpButtons.RowCount.ToString());
            }
            tlpButtons.Controls.Add(container);
        }
    }

This is what it outputs: Let me explain what you're seeing.

I have TableLayoutPanel tlpOuter (pink) with 1 column (100%) and 2 rows. Row 1: AutoSize, Row 2: 100%

In the first row I have another TableLayoutPanel tplButtons (orange) with 1 column (100%) and 1 row (AutoSize, GrowStyle: Rows)

output

Now I can't figure out why the 2nd FlowLayoutPanel (yellow) is so large. It shouldn't be. It is exactly the same as the first panel (it's in a foreach) and yet, it adds all this whitespace (yellowspace).

What I found, when debugging line-by-line, is that the second panel grows as the buttons are added (as if it thinks they get a new line instead being placed side-side if it can) while it does not do that while adding the buttons to the first panel.

UPDATE: So I removed the docking from the flowLayoutPanels and I can now see the problem is actually the TableLayoutPanel tlpButtons!

From what I can gather, it is sizing the Table as if the controls inside had no docking. Look:enter image description here

So the question remains, why does this TableLayoutPanel not account for the docking of the FLP's?

Nimesco
  • 688
  • 4
  • 13
  • Take a look here. http://stackoverflow.com/questions/15880458/flowlayoutpanel-autosize-only-in-vertical – Zath Mar 02 '17 at 12:55
  • I have updated the question. it is a problem with the TableLayoutPanel – Nimesco Mar 02 '17 at 13:09
  • I would appreciate whoever downvoted, you also state why exactly you did so. – Nimesco Mar 02 '17 at 13:33
  • `I have TableLayoutPanel tlpOuter (pink) with 1 column (100%) and 2 rows. Row 1: AutoSize, Row 2: 100%` I think that's your problem (if I understand the issue correctly). Make both rows 50%. – LarsTech Mar 02 '17 at 22:32

0 Answers0