行才怪,要用消息处理的。在程序窗口之外的鼠标键盘行为是不会触发窗体事件的,用API吧,参考函数GetCapture,GetCursorPos。

解决方案 »

  1.   

    原因是VB Form的LostFocus和Deactive只能在本程序内发生,一个简单的解决办法是增加一个几百毫秒的定时器,加入程序:
    Private Declare Function GetActiveWindow Lib "user32" () As LongPrivate Sub Timer1_Timer()
        If GetActiveWindow() <> hWnd Then End
    End Sub
      

  2.   

    Timer.Interval = 50
    sub Timer1_OnTimer()
        GetCursorPos x, y   ;This is API
        if x < scalex(Left, vbTwips, vbPixels) or x > .... ; 判断是否在Form外
            end
        endif
    end sub