Szerkesztés

Megosztás a következőn keresztül:


TableLayoutPanel.GetControlFromPosition(Int32, Int32) Method

Definition

Returns the child control occupying the specified position.

public:
 System::Windows::Forms::Control ^ GetControlFromPosition(int column, int row);
public System.Windows.Forms.Control GetControlFromPosition (int column, int row);
public System.Windows.Forms.Control? GetControlFromPosition (int column, int row);
member this.GetControlFromPosition : int * int -> System.Windows.Forms.Control
Public Function GetControlFromPosition (column As Integer, row As Integer) As Control

Parameters

column
Int32

The column position of the control to retrieve.

row
Int32

The row position of the control to retrieve.

Returns

The child control occupying the specified cell; otherwise, null if no control exists at the specified column and row, or if the control has its Visible property set to false.

Exceptions

Either column or row (or both) is less than 0.

Examples

The following code example enumerates all the cell positions in the TableLayoutPanel by looping through the columns and rows given by ColumnCount and RowCount, and then calling the GetControlFromPosition method to retrieve the control at each cell.

private void getcontrolFromPosBtn_Click(
    System.Object sender, 
    System.EventArgs e)
{
    int i = 0;
    int j = 0;
    Trace.WriteLine(this.TableLayoutPanel1.ColumnCount);
    Trace.WriteLine(this.TableLayoutPanel1.RowCount);

    for(i=0; i<=this.TableLayoutPanel1.ColumnCount; i++)
    {
        for(j=0; j<=this.TableLayoutPanel1.RowCount; j++)
        {
            Control c = this.TableLayoutPanel1.GetControlFromPosition(i, j);

            if( c != null )
            {
                Trace.WriteLine(c.ToString());
            }
        }
    }
}
Private Sub getcontrolFromPosBtn_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles getcontrolFromPosBtn.Click


    Trace.WriteLine(Me.TableLayoutPanel1.ColumnCount)
    Trace.WriteLine(Me.TableLayoutPanel1.RowCount)

    For i As Integer = 0 To Me.TableLayoutPanel1.ColumnCount - 1
        For j As Integer = 0 To Me.TableLayoutPanel1.RowCount - 1

            Dim c As Control = Me.TableLayoutPanel1.GetControlFromPosition(i, j)

            If c IsNot Nothing Then

                Trace.WriteLine(c.ToString())

            End If
        Next
    Next

End Sub

Remarks

The column and row position values are zero based.

Applies to

See also