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,包含 ColumnStyle 控制項中每一個資料行的 TableLayoutPanel

屬性

範例

下列程式碼範例會在 ColumnStyle 按一下 時 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. 設定 ColumnStyleAbsolute 為 的資料行會先視為,並配置其固定寬度。

  2. 設定 ColumnStyleAutoSize 為 的資料行會調整為其內容的大小。

  3. 剩餘的空間會分割在設定為 Percent 的資料 ColumnStyle 行之間。

適用於

另請參閱