Olvasás angol nyelven Szerkesztés

Megosztás a következőn keresztül:


TableLayoutPanel.ColumnStyles Property

Definition

Gets a collection of column styles for the TableLayoutPanel.

[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.TableLayoutColumnStyleCollection ColumnStyles { get; }

Property Value

A TableLayoutColumnStyleCollection containing a ColumnStyle for each column in the TableLayoutPanel control.

Attributes

Examples

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 = 
        this.TableLayoutPanel1.ColumnStyles;

    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;
        }
        else
        {
            // Set the column width to 50 pixels.
            style.SizeType = SizeType.Absolute;
            style.Width = 50;
        }
    }
}

Remarks

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.

Applies to

Termék Verziók
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

See also