TableLayoutPanel.GetControlFromPosition(Int32, Int32) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回占据指定位置的子控件。
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
要检索的控件的行位置。
返回
占用指定单元格的子控件;否则, null 如果指定列和行中不存在任何控件,或者控件的属性 Visible 设置为 false。
例外
column或row(或两者)都小于 0。
示例
下面的代码示例通过循环访问给定TableLayoutPanelColumnCount的列和行来枚举该单元格中的所有RowCount单元格位置,然后调用GetControlFromPosition该方法以检索每个单元格中的控件。
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
注解
列和行位置值基于零。