遍历picturebox内多层控件
一个picturebox作为容器,里面放入多种控件,并且其中的容器控件作为容器继续存放其他控件,怎样遍历找到picturebox内所有控件并修改属性。
[解决办法]
'以下示例列出所有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