Auto Resize TableLayoutPanel

I have a programmatically created TableLayoutPanel. It works fine, but I could not find something: how can I make it size columns automatically when resizing the form? The panel is set to Dock.Top, and when I resize the form, rather than the size of each column in percent, only the last column grows. What can I do for this? Here, as I add ColumnStyle for each column:

this.tablePanelFilter.ColumnStyles.Add(
  new ColumnStyle(SizeType.Percent,Convert.ToSingle(
     Math.Ceiling((decimal)100 / (decimal)columnCount))));
+3
source share
3 answers

Adding this code to the form. The resection event resolved the issue:

this.tablePanelFilter.ColumnStyles.Clear();

            for (int i = 0; i < this.tablePanelFilter.ColumnCount; i++)
            {
                ColumnStyle c = new ColumnStyle();
                c.SizeType = SizeType.Percent;
                c.Width = Convert.ToSingle(Math.Ceiling((decimal)100 / (decimal)this.tablePanelFilter.ColumnCount));
                this.tablePanelFilter.ColumnStyles.Add(c);
            }
+1
source

Have you tried setting ColumnStyles parameters to SizeType.Percent?

http://msdn.microsoft.com/en-us/library/system.windows.forms.tablelayoutpanel.columnstyles.aspx

+2

Do you clear ColumnStyles first? Use a debugger and / or some code to make sure you have as many ColumnStyles columns as you have columns.

+1
source

Source: https://habr.com/ru/post/1718709/


All Articles