我正在尝试以递归方式遍历窗口中的组件,但它永远不会通过窗口到达其子组件。我做错了什么?
Public Sub fixUIIn(ByRef comp As System.ComponentModel.Component, ByVal style As SByte)
Debug.WriteLine(comp)
If TypeOf comp Is System.Windows.Forms.ContainerControl Then
Dim c As System.Windows.Forms.ContainerControl
c = comp
c.BackColor = getColor(style, PART_BACK)
c.ForeColor = getColor(style, PART_TEXT)
If ((comp.Container IsNot Nothing) AndAlso (comp.Container.Components IsNot Nothing)) Then
For i As Integer = 0 To comp.Container.Components.Count() Step 1
fixUIIn(comp.Container.Components.Item(i), style)
Next
End If
comp = c
End If
End Sub
答案 0 :(得分:0)
不确定为什么要从Component而不是Control开始,但是如果你可以从Control(例如表单)开始,你可以
试
Public Sub fixUIIn(ByRef comp As System.Windows.Forms.Control ByVal style As SByte)
Debug.WriteLine(comp)
comp.BackColor = getColor(style, PART_BACK)
comp.ForeColor = getColor(style, PART_TEXT)
If (comp.Controls IsNot Nothing) Then
For i As Integer = 0 To comp.Controls.Count()
fixUIIn(comp.Controls.Item(i), style)
Next
End If
End Sub