Share via


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 呼叫,面板會在設計階段新增至其子控制項。

適用於

另請參閱