在 TableLayoutPanel 中查找元素

Find elements in TableLayoutPanel

我正在学习c#。

我想获取所有添加到 TableLayoutPanel 中的标签。

Control c2 = this.ReportTable.GetControlFromPosition(col,row+1);

Trace.WriteLine(c2.GetType());
if (c2.GetType().Equals(typeof(TableLayoutPanel)))
{
    // Put loop to iterate.  
}

ReportTable 也是 TableLayoutPanelc2.GetType() 正在给予 TableLayoutPanel。我无法在 c2.GetType().RowCount

上应用 RowCount 方法

请帮助我在 TableLayoutPanel 内部迭代,它在其他 TableLayoutPanel 内部与其他元素

没关系,我想通了。我想做 TypeCasting 来控制

Control c2 = this.ReportTable.GetControlFromPosition(col,row+1);
                                  Trace.WriteLine(c2.GetType());
                                  if (c2.GetType().Equals(typeof(TableLayoutPanel)))
                                  {
                                      TableLayoutPanel tp = (TableLayoutPanel)c2;

                                      // get all labels in table  
                                      foreach(Control ctr in tp.Controls){
                                          Trace.WriteLine(ctr .GetType());
                                      }

                                  }