編輯

共用方式為


TableLayoutPanel.GrowStyle Property

Definition

Gets or sets a value indicating whether the TableLayoutPanel control should expand to accommodate new cells when all existing cells are occupied.

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

Property Value

A TableLayoutPanelGrowStyle indicating the growth scheme. The default is AddRows.

Exceptions

The property value is invalid for the TableLayoutPanelGrowStyle enumeration.

Examples

The following code example sets the value of the GrowStyle property depending on the selected RadioButton. At run time, when the user clicks on the button labeled Test GrowStyle, a Button control is added to the TableLayoutPanel control. If the TableLayoutPanel control is full, it expands by adding a row or column, or it raises an exception, depending on the value of 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

Remarks

By default, the TableLayoutPanel control expands downward by adding rows.

Note

If an attempt is made to add a control to a full TableLayoutPanel control, and the value of GrowStyle is FixedSize, then an ArgumentException is thrown.

Applies to

See also