读书人

遍历picturebox内多层控件解决方法

发布时间: 2012-01-26 19:40:46 作者: rapoo

遍历picturebox内多层控件
一个picturebox作为容器,里面放入多种控件,并且其中的容器控件作为容器继续存放其他控件,怎样遍历找到picturebox内所有控件并修改属性。


[解决办法]

VBScript code
'以下示例列出所有Picture1内的控件Private Function IsInside(ByVal SubControl As Control, ByVal Container As Control) As Boolean    Dim ctl As Control    Set ctl = SubControl    While Not ctl.Container Is Me        If ctl.Container Is Container Then            IsInside = True            Exit Function        End If        Set ctl = ctl.Container    WendEnd FunctionPrivate Sub Command1_Click()    Dim ctl As Control    For Each ctl In Me.Controls        If IsInside(ctl, Picture1) Then            Debug.Print ctl.Name        End If    NextEnd Sub 

读书人网 >VB

热点推荐