共用方式為


TableLayoutPanel.ColumnStyles 屬性

定義

獲得一組欄位樣式集合。TableLayoutPanel

public:
 property System::Windows::Forms::TableLayoutColumnStyleCollection ^ ColumnStyles { System::Windows::Forms::TableLayoutColumnStyleCollection ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.TableLayoutColumnStyleCollection ColumnStyles { get; }
[<System.ComponentModel.Browsable(false)>]
member this.ColumnStyles : System.Windows.Forms.TableLayoutColumnStyleCollection
Public ReadOnly Property ColumnStyles As TableLayoutColumnStyleCollection

屬性值

TableLayoutColumnStyleCollection A 包含控制項中每一欄TableLayoutPanel的 aColumnStyle

屬性

範例

以下程式碼範例 ColumnStyle 設定了點擊 a Button 時每欄的屬性。

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;
        }
    }
}
Private Sub toggleColumnStylesBtn_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles toggleColumnStylesBtn.Click

    Dim styles As TableLayoutColumnStyleCollection = _
    Me.TableLayoutPanel1.ColumnStyles

    For Each style As ColumnStyle In styles

        If style.SizeType = SizeType.Absolute Then

            style.SizeType = SizeType.AutoSize

        ElseIf style.SizeType = SizeType.AutoSize Then

            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

        End If

    Next

End Sub

備註

使用該 ColumnStyles 屬性來存取特定欄位的樣式屬性。 你可以利用類別 ColumnStyle 成員來設定表格中各欄位的特性。

當控制 TableLayoutPanel 項排列欄位時,會依下列順序分配優先順序 ColumnStyle

  1. 設定為 的Absolute欄位ColumnStyle先被考慮,並分配其固定寬度。

  2. 設定 ColumnStyle 為 的 AutoSize 欄位大小依其內容物大小調整。

  3. 剩餘空間被分配到欄位,欄位 ColumnStyle 設為 Percent

適用於

另請參閱