我向工程中添加了一个UserControl,并向其中添加了若干个Lable和TextBox控件,
在主Form中,我将该UserControl添加到Form上。
在Form有Me.Controls这个属性,可以遍历Form下的所有控件,但没法遍历UserControl
下的控件,有哪位VB高手帮忙指点一下。

解决方案 »

  1.   

    dim obj as objectfor each obj in me
        if typeof obj is Usercontrol then
            '处理语句
        endif
    next obj
      

  2.   

    你用它试试
    【声明】
    Public Declare Function EnumChildWindows Lib "user32" Alias "EnumChildWindows" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
    【说明】
    为指定的父窗口枚举子窗口
    【返回值】
    Long,非零表示成功,零表示失败
    【参数表】
      hWndParent -----  Long,欲枚举子窗口的父窗口的句柄  lpEnumFunc -----  Long,为每个子窗口调用的函数的指针。用AddressOf运算符获得函数在一个标准模块中的地址  lParam ---------  Long,在枚举期间,传递给dwcbkd32.ocx定制控件之EnumWindows事件的值。这个值的含义是由程序员规定的。(原文:Value
      that is passed to the EnumWindows event of the dwcbkd32.ocx custom control during
      enumeration. The meaning of this value is defined by the programmer.)
    【其它】
    在vb4下要求dwcbkd32.ocx定制控件。子窗口下属的子窗口也可由这个函数枚举
      

  3.   

    按treewith(开心~~一切从幼稚开始)提示的方法行不通啊!:-(我正准备用yefanqiu(叶帆)的方法试试,但还不知道行得通否,不过,这里先谢谢各位大侠了。