2011-04-27 25 views
1

我想循環遍歷窗口中的組件,但它永遠不會通過窗口到其子組件。我究竟做錯了什麼?recusive循環通過在VB中不工作的組件

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

不知道爲什麼你開始一個組件,而不是控制,但如果你可以用一個控制(如表格)開始,你可以

嘗試

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 
+0

謝謝...一旦我得到Visual Studio GUI生成器不會失敗,我會實現它 – Supuhstar 2011-04-28 00:32:55