TableLayoutPanel.GetControlFromPosition(Int32, Int32) 方法

定義

傳回佔用指定之位置的子控制項。

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

參數

column
Int32

要擷取之控制項的資料行位置。

row
Int32

要擷取之控制項的資料列位置。

傳回

佔用指定儲存格的子控制項;如果指定的資料行和資料列中沒有任何控制項,或是控制項的 Visible 屬性設為 null 則為 false

例外狀況

column 或 / 及 row 小於 0。

範例

下列程式碼範例會藉由迴圈查看 和 RowCount 所提供的 ColumnCount 資料行和資料列,然後呼叫 GetControlFromPosition 方法來擷取每個儲存格上的 控制項,以列舉 中的所有 TableLayoutPanel 儲存格位置。

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

備註

資料行和資料列位置值是以零起始。

適用於

另請參閱