如何在 VB6 中编辑特定框架上的 GUI 元素

How to edit GUI elements on a specific frame in VB6

如何访问控件的嵌套控件?

我的用户界面上有几个框架,每个框架都包含几个其他控件(如标签、按钮等)。我必须遍历帧并更改特定帧的 children 的内容(例如,在标签中设置另一个文本)。

到目前为止,我遍历了我的框架的所有控件,并检查循环控制变量中的控件是否是应该进行更改的框架。

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

现在我在控制变量中有了框架,但问题是我无法访问嵌套标签来更改标签的标题。我能做什么?

您需要查看每个控件的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