TableLayoutPanel.RowStyles 属性

定义

获取 TableLayoutPanel 的行样式的集合。Gets a collection of row styles for the TableLayoutPanel.

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

属性值

属性

示例

下面的代码示例在单击 Button 时设置每行的 RowStyle 属性。The following code example sets the RowStyle properties of each row when a Button is clicked.

private void toggleRowStylesBtn_Click(
    System.Object sender, 
    System.EventArgs e)
{
    TableLayoutRowStyleCollection styles = 
        this.TableLayoutPanel1.RowStyles;

    foreach( RowStyle style in styles )
    {
        if (style.SizeType==SizeType.Absolute)
        {
            style.SizeType = SizeType.AutoSize;
        }
        else if(style.SizeType==SizeType.AutoSize)
        {
            style.SizeType = SizeType.Percent;

            // Set the row height to be a percentage
            // of the TableLayoutPanel control's height.
            style.Height = 33;
        }
        else
        {

            // Set the row height to 50 pixels.
            style.SizeType = SizeType.Absolute;
            style.Height = 50;
        }
    }
}
Private Sub toggleRowStylesBtn_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles toggleRowStylesBtn.Click

    Dim styles As TableLayoutRowStyleCollection = _
    Me.TableLayoutPanel1.RowStyles

    For Each style As RowStyle In styles

        If style.SizeType = SizeType.Absolute Then

            style.SizeType = SizeType.AutoSize

        ElseIf style.SizeType = SizeType.AutoSize Then

            style.SizeType = SizeType.Percent

            ' Set the row height to be a percentage
            ' of the TableLayoutPanel control's height.
            style.Height = 33

        Else

            ' Set the row height to 50 pixels.
            style.SizeType = SizeType.Absolute
            style.Height = 50

        End If

    Next

End Sub

注解

使用 RowStyles 属性访问特定行的样式属性。Use the RowStyles property to access the style properties of specific rows. 您可以使用 RowStyle 类的成员设置表中各个行的特征。You can use members of the RowStyle class to set the characteristics of individual rows in the table.

TableLayoutPanel 控件排列其行时,它会按以下顺序将优先级分配给每个 RowStyleWhen the TableLayoutPanel control arranges its rows, it assigns priorities to each RowStyle in the following order:

  1. RowStyle 设置为 Absolute 的行将首先被视为,并分配其固定高度。Rows with RowStyle set to Absolute are considered first, and their fixed heights are allocated.

  2. RowStyle 设置为 AutoSize 的行将调整为其内容大小。Rows with RowStyle set to AutoSize are sized to their contents.

  3. 剩余空间在 RowStyle 设置为 Percent的行间划分。Remaining space is divided among rows with RowStyle set to Percent.

适用于

另请参阅