如何访问控件的嵌套控件?
我的用户界面上有几个框架,每个框架都包含其他几个控件(如标签,按钮......)。我必须迭代帧并更改特定帧的子项的内容(例如,在标签中设置另一个文本)。
到目前为止,我遍历框架的所有控件,并检查循环控制变量中的控件是否应该是更改的框架。
Dim cntrl As Control
For Each cntrl In Controls
'Debug.Print cntrl.Name // here I get all controls on the form
If cntrl.Name = "Frame_Name" Then
If cntrl.Index = index Then
Debug.Print "true" ' here the caption of nested components should be changed
End If
End If
Next
现在我在控制变量中有框架,但问题是我无法访问嵌套标签来更改标签的标题。我该怎么办?
答案 0 :(得分:2)
您需要查看每个控件的Container属性。以下代码应该给你一个想法:
Dim cntrl As Control
For Each cntrl In Controls
If cntrl.Container.Name = "Frame_Name" Then
Debug.Print cntrl.Name & " is nested in the specified frame"
End If
Next