延时求教高手:我用函数sleep做了一个延时效果,但是在sleep起作用时,其他好像也被延时,求教解决方法如:picVolume为picturebox控件Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)Private Sub Command1_Click()
Sleep (6000)
End SubPrivate Sub picVolume_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbLeftButton Then
        If X < 0 Then X = 0
        If X > picVolume.Width Then X = picVolume.Width
                FindVolume CLng(X)
    End If
End Sub
Private Sub picVolume_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    picVolume_MouseDown Button, Shift, X, Y
End Sub
Private Sub FindVolume(lVol As Long)
    lVolume = lVol
    picVolume.Cls
    picVolume.Line (0, 0)-(lVol, picVolume.Height), &HC0E0FF, BF
End Sub

解决方案 »

  1.   

    谢谢!!!我想在按下COMMAND1后,picVolume的代码执行不受影响,谢谢!!!
      

  2.   

    Private Sub Command1_Click()
    Dim a As Long
    a = Timer
    Do Until Timer > a + 6: DoEvents: Loop
    End Sub
      

  3.   

    把下列代码放到模块里
    Option ExplicitPrivate Declare Function SetTimer Lib "user32" ( _
                    ByVal hWnd As Long, _
                    ByVal nIDEvent As Long, _
                    ByVal uElapse As Long, _
                    ByVal lpTimerFunc As Long) As Long
    Private Declare Function KillTimer Lib "user32" ( _
                    ByVal hWnd As Long, _
                    ByVal nIDEvent As Long) As LongPrivate lnghWnd As Long
    Sub Test()    KillTimer lnghWnd, 1
        '添加COMMAND1要执行的代码
    End SubSub Delay(ByVal hWnd As Long, ByVal lngT As Long)
        lnghWnd = hWnd
        SetTimer lnghWnd, 1, lngT, AddressOf Test
    End Sub下面是Command1的Click事件,延时3秒
    Private Sub Command1_Click()
        Call Delay(Me.hWnd, 3000)
    End Sub