|
-
Sep 13th, 2010, 03:42 PM
#1
Thread Starter
Addicted Member
[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.
-
Sep 13th, 2010, 04:10 PM
#2
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.
-
Sep 13th, 2010, 04:12 PM
#3
Fanatic Member
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.
-
Sep 13th, 2010, 04:36 PM
#4
Thread Starter
Addicted Member
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?
-
Sep 13th, 2010, 04:38 PM
#5
Thread Starter
Addicted Member
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?
-
Sep 13th, 2010, 04:49 PM
#6
Re: When the mouse cursor leave the picturebox do something
 Originally Posted by Programmation
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.
-
Sep 13th, 2010, 05:09 PM
#7
Thread Starter
Addicted Member
Re: When the mouse cursor leave the picturebox do something
Thank you very very much Edgemeal,your post has Rated
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|