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 面板在设计时添加到其子控件的属性调用。

适用于

另请参阅