2017-05-16 24 views
1

如何訪問控件的嵌套控件?如何編輯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 

現在我有控制變量中的框架,但問題是我無法訪問嵌套標籤來更改標籤的標題。我能做什麼?

回答

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