以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]请教怎么遍历窗口表  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=177043)

--  作者:昱飞哥
--  发布时间:2022/5/7 13:53:00
--  [求助]请教怎么遍历窗口表
窗口中,有个页面集合TabControl1,页面集合中含有多个Table,我写了下面的代码遍历这些Table,报错。

For Each c As WinForm.Control In e.Form.Controls("TabControl1").controls
    If Typeof c Is WinForm.Table Then \'判断控件是否是Table
        Dim t As WinForm.Table = c \'使用特定类型的变量引用控件
        MessageBox.Show(c.Table.name)
    End If
Next

我的疑问有2个:
1、上面的代码怎么修改?
2、如果我除了页面集合TabControl1之外还有其他的容器控件,比方panel1,要是panel1里面也有Table,那这个Table也能一起遍历出来吗?

--  作者:有点蓝
--  发布时间:2022/5/7 14:11:00
--  
For Each p As WinForm.TabPage In e.Form.Controls("TabControl1").tabpages
    For Each c As WinForm.Control In p.children
        If TypeOf c Is WinForm.Table Then \'判断控件是否是Table
            Dim t As WinForm.Table = c \'使用特定类型的变量引用控件
            MessageBox.Show(t.name)
        ElseIf TypeOf c Is WinForm.Panel Then
            Dim pnl As WinForm.Panel = c
            For Each c2 As WinForm.Control In pnl.children
                If TypeOf c2 Is WinForm.Table Then \'判断控件是否是Table
                    Dim t2 As WinForm.Table = c \'使用特定类型的变量引用控件
                    MessageBox.Show(t2.name)
                End If
            Next
        End If
    Next
Next