Results 1 to 7 of 7

Thread: [RESOLVED] When the mouse cursor leave the picturebox do something

  1. #1

    Thread Starter
    Addicted Member Programmation's Avatar
    Join Date
    Nov 2009
    Posts
    161

    Resolved [RESOLVED] When the mouse cursor leave the picturebox do something

    Hello every one

    I using the mousemove event for something but how do i know if the mouse on the picture box or its leave it ?

    For example i want show a msgbox when the mouse cursor is out the picture box border

    Thanks for all
    Last edited by Programmation; Sep 13th, 2010 at 03:48 PM.
    Just Do It!

  2. #2
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: When the mouse cursor leave the picturebox do something

    If the pic box is smaller then its container you could use the container to check a variable if set.

    Code:
    Option Explicit
    Dim MouseMovePB As Boolean
    
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If MouseMovePB = True Then
            MouseMovePB = False
            MsgBox "Mouse was in picturebox and has left.", vbInformation
        End If
    End Sub
    
    Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        MouseMovePB = True
    End Sub
    But if the pic box is say at the very edges of a form you'd want to use something else, one way is using API like SetCapture & ReleaseCapture.

  3. #3
    Fanatic Member
    Join Date
    Oct 2009
    Location
    Missouri
    Posts
    770

    Re: When the mouse cursor leave the picturebox do something

    Use this
    Code:
    Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Public Type POINTAPI
        X As Long
        Y As Long
    End Type
    Then do a collision with the mouse, and the picture box.
    Rate my post if i helped you!


    Button Configuration Control For VB6 GetAsyncKeyState
    I'm the 7th best high school programmer in the nation!(according to SkillsUSA Nationals)(Used C#.Net)

  4. #4

    Thread Starter
    Addicted Member Programmation's Avatar
    Join Date
    Nov 2009
    Posts
    161

    Re: When the mouse cursor leave the picturebox do something

    Thank you very much Edgemeal but i dont want use the Form_MouseMove.
    Thank you Gamemaster1494 but can u write a simple example code for this function?
    Just Do It!

  5. #5

    Thread Starter
    Addicted Member Programmation's Avatar
    Join Date
    Nov 2009
    Posts
    161

    Re: When the mouse cursor leave the picturebox do something

    Thank you very much Edgemeal but i dont want use the Form_MouseMove.
    Thank you Gamemaster1494 but can u write a simple example code for this function?
    Just Do It!

  6. #6
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: When the mouse cursor leave the picturebox do something

    Quote Originally Posted by Programmation View Post
    Thank you very much Edgemeal but i dont want use the Form_MouseMove.
    Another way using API...
    Code:
    Option Explicit
    Private Declare Function GetCapture Lib "user32" () As Long
    Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function ReleaseCapture Lib "user32" () As Long
    
    Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
         
         With Picture1
            If GetCapture() = .hwnd Then
                If ((X < 0) Or (X > .ScaleWidth)) Or ((Y < 0) Or (Y > .ScaleHeight)) Then
                    ' mouse outside control bounds, release
                    Call ReleaseCapture
                    MsgBox "Mickey Mouse has left the building!", vbInformation
                End If
            Else ' mouse within control bounds, set capture
                Call SetCapture(.hwnd)
            End If
        End With
            
    End Sub
    Last edited by Edgemeal; Sep 13th, 2010 at 04:54 PM.

  7. #7

    Thread Starter
    Addicted Member Programmation's Avatar
    Join Date
    Nov 2009
    Posts
    161

    Re: When the mouse cursor leave the picturebox do something

    Thank you very very much Edgemeal,your post has Rated
    Just Do It!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width