TableLayoutPanel.GetRow(Control) 方法

定义

返回指定子控件的行位置。

public:
 int GetRow(System::Windows::Forms::Control ^ control);
public int GetRow(System.Windows.Forms.Control control);
member this.GetRow : System.Windows.Forms.Control -> int
Public Function GetRow (control As Control) As Integer

参数

control
Control

TableLayoutPanel子控件。

返回

的行位置 control,或 -1 的位置 control 由确定 LayoutEngine

例外

controlnull

control 不是可以按此 LayoutEngine方式排列的类型。

示例

下面的代码示例枚举了该方法中的每个 TableLayoutPanel 子控件,并查找每个 GetRow 子控件的行索引。

private void getRowBtn_Click(
    System.Object sender, 
    System.EventArgs e)
{
    foreach ( Control c in this.TableLayoutPanel1.Controls )
    {
        Trace.WriteLine(this.TableLayoutPanel1.GetRow(c));
    }
}
Private Sub getRowBtn_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles getRowBtn.Click

    Dim c As Control
    For Each c In Me.TableLayoutPanel1.Controls

        Trace.WriteLine(Me.TableLayoutPanel1.GetRow(c))

    Next

End Sub

注解

如果 control 跨两行或多行,该方法 GetRow 将返回最低的行索引。

行位置值基于零,因此可以将它用作返回的 GetRowHeights数组的索引。

此方法由 Row 面板在设计时添加到其子控件的属性调用。

若要获取实际位置,即使其位置 control由其 LayoutEngine确定,也调用该方法 GetPositionFromControl

适用于

另请参阅