Share via


TableLayoutPanel.SetColumn(Control, Int32) 方法

定義

設定指定之子控制項的資料行位置。

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

參數

control
Control

要移到另一個資料行的控制項。

column
Int32

control 將移到其中的資料行。

範例

下列程式碼範例會 SetColumn 使用 方法來交換 控制項中包含的兩個 TableLayoutPanel 控制項。 此範例假設控制項至少有兩個 TableLayoutPanel 資料列。

private void swapControlsBtn_Click(
    System.Object sender, 
    System.EventArgs e)
{
    Control c1 = this.TableLayoutPanel1.GetControlFromPosition(0, 0);
    Control c2 = this.TableLayoutPanel1.GetControlFromPosition(0, 1);

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

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

    If c1 IsNot Nothing And c2 IsNot Nothing Then

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

    End If

End Sub

備註

方法會將 SetColumn 控制項移至 中的 TableLayoutPanel 另一個資料行。 資料行和資料列具有以零起始的索引。 將資料行位置設定為 -1 會指定控制項會流向第一個空白儲存格。

這個方法會將資料表配置重新套用至 中的所有 TableLayoutPanel 控制項。

這個方法是由 Column 屬性所呼叫,面板會在設計階段新增至其子控制項。

適用於

另請參閱