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



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

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

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

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

最新更新