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 property 呼叫,面板在設計時將其加入子控制項。

適用於

另請參閱