递归循环遍历组件在 VB 中不起作用

发布于 2024-11-03 17:35:56 字数 733 浏览 0 评论 0原文

我试图递归地循环遍历窗口中的组件,但它永远不会越过窗口到达其子组件。我做错了什么?

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

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.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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

太阳哥哥 2024-11-10 17:35:56

不确定为什么从组件而不是控件开始,但如果可以从控件(例如表单)开始,您可以

尝试

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文