TableLayoutPanel.SetRow(Control, Int32) 方法

定义

设置指定子控件的行位置。

public:
 void SetRow(System::Windows::Forms::Control ^ control, int row);
public void SetRow(System.Windows.Forms.Control control, int row);
member this.SetRow : System.Windows.Forms.Control * int -> unit
Public Sub SetRow (control As Control, row As Integer)

参数

control
Control

要移动到另一行的控件。

row
Int32

要移动到的 control 行。

示例

下面的代码示例使用 SetColumn 该方法交换控件中包含的两个 TableLayoutPanel 控件。 该示例假定具有 TableLayoutPanel 至少两行的控件。

private void swapRowsBtn_Click(
    System.Object sender, 
    System.EventArgs e)
{

    Control c1 = this.TableLayoutPanel1.GetControlFromPosition(0, 0);
    Control c2 = this.TableLayoutPanel1.GetControlFromPosition(1, 0);

    if ( c1 !=null && c2 != null )
    {
        this.TableLayoutPanel1.SetRow(c2, 0);
        this.TableLayoutPanel1.SetRow(c1, 1);
    }
}
Private Sub swapRowsBtn_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles swapRowsBtn.Click

    Dim c1 As Control = Me.TableLayoutPanel1.GetControlFromPosition(0, 0)
    Dim c2 As Control = Me.TableLayoutPanel1.GetControlFromPosition(1, 0)

    If c1 IsNot Nothing And c2 IsNot Nothing Then

        Me.TableLayoutPanel1.SetRow(c2, 0)
        Me.TableLayoutPanel1.SetRow(c1, 1)

    End If


End Sub

注解

该方法将 SetRow 控件移动到控件中的 TableLayoutPanel 另一行。 列和行具有从零开始的索引。 将行位置设置为 -1 指定控件将流向第一个空单元格。

此方法将表布局重新应用到该控件中的所有 TableLayoutPanel控件。

此方法由 Row 面板在设计时添加到其子控件的属性调用。

适用于

另请参阅