Uredi

Deli z drugimi prek


TableLayoutPanel.SetRow(Control, Int32) Method

Definition

Sets the row position of the specified child control.

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)

Parameters

control
Control

The control to move to another row.

row
Int32

The row to which control will be moved.

Examples

The following code example uses the SetColumn method to swap two controls contained within a TableLayoutPanel control. The example assumes a TableLayoutPanel control with at least two rows.

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

Remarks

The SetRow method moves the control to another row in the TableLayoutPanel control. The columns and rows have zero-based indexes. Setting the row position to -1 specifies that the control will flow to the first empty cell.

This method reapplies the table layout to all controls in the TableLayoutPanel.

This method is called by the Row property, which the panel adds to its child controls at design time.

Applies to

See also