TableLayoutPanel.ColumnStyles Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Gets a collection of column styles for the TableLayoutPanel.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public TableLayoutColumnStyleCollection ColumnStyles { get; }

Use the ColumnStyles property to access the style properties of specific columns. You can use members of the ColumnStyle class to set the characteristics of individual columns in the table.

When the TableLayoutPanel control arranges its columns, it assigns priorities to each ColumnStyle in the following order:

  1. Columns with ColumnStyle set to Absolute are considered first, and their fixed widths are allocated.

  2. Columns with ColumnStyle set to AutoSize are sized to their contents.

  3. Remaining space is divided among columns with ColumnStyle set to Percent.

The following code example sets the ColumnStyle properties of each column when a Button is clicked.

  private void toggleColumnStylesBtn_Click(
System.Object sender, 
System.EventArgs e)
TableLayoutColumnStyleCollection styles = 

      foreach( ColumnStyle style in styles )
          if( style.SizeType == SizeType.Absolute )
              style.SizeType = SizeType.AutoSize;
          else if( style.SizeType == SizeType.AutoSize )
              style.SizeType = SizeType.Percent;

              // Set the column width to be a percentage
              // of the TableLayoutPanel control's width.
              style.Width = 33;
              // Set the column width to 50 pixels.
              style.SizeType = SizeType.Absolute;
              style.Width = 50;

.NET Framework
Available since 2.0
Return to top