共用方式為


TableLayoutPanel.GrowStyle 屬性

定義

取得或設定值,指出當佔用所有現有的儲存格時,TableLayoutPanel 控制項是否應該擴充來容納新的儲存格。

public:
 property System::Windows::Forms::TableLayoutPanelGrowStyle GrowStyle { System::Windows::Forms::TableLayoutPanelGrowStyle get(); void set(System::Windows::Forms::TableLayoutPanelGrowStyle value); };
public System.Windows.Forms.TableLayoutPanelGrowStyle GrowStyle { get; set; }
member this.GrowStyle : System.Windows.Forms.TableLayoutPanelGrowStyle with get, set
Public Property GrowStyle As TableLayoutPanelGrowStyle

屬性值

TableLayoutPanelGrowStyle

TableLayoutPanelGrowStyle,表示擴充配置。 預設為 AddRows

例外狀況

此屬性值對 TableLayoutPanelGrowStyle 列舉型別無效。

範例

下列程式碼範例會根據選取 RadioButtonGrowStyle 來設定 屬性的值。 在執行時間,當使用者按一下標示為 Test GrowStyle 的按鈕時, Button 控制項就會新增至 TableLayoutPanel 控制項。 TableLayoutPanel如果控制項已滿,它會藉由加入資料列或資料行來展開,或根據 的值 GrowStyle 引發例外狀況。

private void growStyleNoneBtn_CheckedChanged(
    System.Object sender, 
    System.EventArgs e)
{
    this.tlpGrowStyle = TableLayoutPanelGrowStyle.FixedSize;
}

private void growStyleAddRowBtn_CheckedChanged(
    System.Object sender, 
    System.EventArgs e)
{
    this.tlpGrowStyle = TableLayoutPanelGrowStyle.AddRows;
}

private void growStyleAddColumnBtn_CheckedChanged(
    System.Object sender, 
    System.EventArgs e)
{
    this.tlpGrowStyle = TableLayoutPanelGrowStyle.AddColumns;
}

private void testGrowStyleBtn_Click(
    System.Object sender, 
    System.EventArgs e)
{
    this.TableLayoutPanel1.GrowStyle = this.tlpGrowStyle;

    try
    {
        this.TableLayoutPanel1.Controls.Add(new Button());
    }
    catch(ArgumentException ex)
    {
        Trace.WriteLine(ex.Message);
    }
}
Private Sub growStyleNoneBtn_CheckedChanged( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles growStyleNoneBtn.CheckedChanged

    Me.tlpGrowStyle = TableLayoutPanelGrowStyle.FixedSize

End Sub

Private Sub growStyleAddRowBtn_CheckedChanged( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles growStyleAddRowBtn.CheckedChanged

    Me.tlpGrowStyle = TableLayoutPanelGrowStyle.AddRows

End Sub

Private Sub growStyleAddColumnBtn_CheckedChanged( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles growStyleAddColumnBtn.CheckedChanged

    Me.tlpGrowStyle = TableLayoutPanelGrowStyle.AddColumns

End Sub

Private Sub testGrowStyleBtn_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles testGrowStyleBtn.Click

    Me.TableLayoutPanel1.GrowStyle = Me.tlpGrowStyle

    Try

        Me.TableLayoutPanel1.Controls.Add(New Button())

    Catch ex As ArgumentException

        Trace.WriteLine(ex.Message)

    End Try

End Sub

備註

TableLayoutPanel 控制項預設會向下加入資料列來展開。

注意

如果嘗試將控制項新增至完整 TableLayoutPanel 控制項,且 的值為 GrowStyle FixedSize ,則會 ArgumentException 擲回 。

適用於

另請參閱