在更新期间禁用 VB6 计时器

Disable VB6 Timer during updates

如何在 TreeView FOR 语句到达最后一项后执行 timer1.enabled=true。当树视图仍在工作时,我的计时器开始计时。

这是我目前的代码。

Private Sub Command17_Click()
    Dim objRootNode As Node
    Dim objChildNode As Node
    Dim iRootCounter As Integer
    Dim iChildCounter As Integer
    Dim countt As Integer
    Dim ii As Integer

    For iRootCounter = 1 To TreeView2.Nodes.Count

        ii = TreeView2.Nodes(iRootCounter).Index

        Set objRootNode = TreeView2.Nodes(iRootCounter)

        If objRootNode.Image = 4 Then

            Set objChildNode = objRootNode.Child ' Gets first child

            For iChildCounter = 1 To objRootNode.Children

                If objChildNode.Image = 3 Then
                    objRootNode.Image = 9
                End If

                Set objChildNode = objChildNode.Next ' Get next node

            Next

        End If

        If TreeView2.Nodes(iRootCounter).Index = TreeView2.Nodes.Count - 0 Then
            If startt = True Then
                Timer1.Enabled = True
                Exit For
            End If
        End If

    Next

End Sub

当我 运行 这段代码时,树视图项目仍处于处理模式,这意味着在我 运行 另一个代码之后它仍在为每个项目更改图像索引,然后触发此按钮.

只需在 TreeView 更新的开头添加 Timer1.Enabled = False。然后,在退出前将其设置回 True。

更好的是,在 Timer1_Timer 事件处理程序中停止计时器:

Private Sub Timer1_Timer()

    ' Stop timer until all code is execute
    Timer1.Enabled = False

    Command17_Click

    ' Restart timer
    Timer1.Enabled = True

End Sub