怎么样判断鼠标离开某个控件,我想做一个按钮控件鼠标放上去显示图1,按下去show图2,离开显图3

解决方案 »

  1.   

    'Command1 style设为1Option ExplicitPrivate Declare Function SetCapture Lib "user32" (ByVal hWnd As Long) As Long
    Private Declare Function ReleaseCapture Lib "user32" () As LongPrivate Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If X > 0 And X < Command1.Width And Y > 0 And Y < Command1.Height Then
            Command1.Picture = LoadPicture(App.Path & "\1.jpg")
            SetCapture Command1.hWnd
        Else
            Command1.Picture = LoadPicture(App.Path & "\3.jpg")
            ReleaseCapture
        End If
    End Sub
      

  2.   

    Option ExplicitPrivate Declare Function SetCapture Lib "user32" (ByVal hWnd As Long) As Long
    Private Declare Function ReleaseCapture Lib "user32" () As LongPrivate Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If X > 0 And X < Command1.Width And Y > 0 And Y < Command1.Height Then
            Command1.Caption = "进入"
            SetCapture Command1.hWnd
        Else
            Command1.Caption = "离开"
            ReleaseCapture
        End If
    End Sub
      

  3.   

    在 Form_MouseMove 处理离开某一控件的事件!VB中不能捕获 MouseLeave 事件,这样变通处理简单一些!
      

  4.   

    用viena(维也纳nn-实心木头人) ( ) 的方法
    另外写:
    Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Command1.Picture = LoadPicture("C:\2.ico")
    End Sub
      

  5.   

    用mousemove很接近,实际中看不出区别,否则太烦.只是控件之间的距离不能太靠近.