Recursive looping through components not working in VB
I'm trying to recursively loop through the components in a window, but it never gets past the window to its sub-components. What am I doing wrong?
Public Sub fixUIIn(ByRef comp As System.Compone开发者_StackOverflow中文版ntModel.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
Not sure why you start with a Component rather than a Control but if you can start with a Control (such as a form) you can
try
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
精彩评论