mouse events for the picture box occur only when the mouse is within the area of the picture box. Areas outside the picture box will trigger mouse events for whatever control or container the mouse is over at the time.
Create a small test project, place a picture box, a label and a few other controls on a form
write some code in the mouse move event of the form and each object. Have that code set the label caption to show what control or container the mouse event was triggered by.
That should give you a pretty good idea of how it is triggered.
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function LoadCursor Lib "user32" Alias "LoadCursorA" _
(ByVal hInstance As Long, ByVal lpCursorName As Long) As Long
Private Declare Function SetCursor Lib "user32" (ByVal hCursor As Long) As Long
Private Const IDC_HAND As Long = 32649
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Private Const SW_SHOW = 5
Private bHovering As Boolean
Private Sub Form_Load()
Picture1.ForeColor = vbBlue
Picture1.Print "www.vbforums.com"
'Picture1.MousePointer = vbCustom
'Picture1.MouseIcon = 32649 'LoadCursor(0, IDC_HAND)
Picture1.ToolTipText = "http://www.vbforums.com/showthread.php?728865-Link-in-textbox"
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
bHovering = True
Label1.Caption = "Mouse is on Form"
End Sub
Private Sub Form_MouseOut()
bHovering = False
Label1.Caption = "Mouse not on Form"
End Sub
Private Sub Picture1_Click()
ShellExecute hwnd, "open", Trim(Picture1.ToolTipText), vbNullString, vbNullString, SW_SHOW
End Sub
Private Sub Picture1_MouseOut()
bHovering = False
Picture1.Cls
Picture1.ForeColor = vbBlue
Picture1.Print "www.vbforums.com"
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
bHovering = True
Picture1.Cls
Picture1.ForeColor = vbRed
Picture1.Print "www.vbforums.com"
'SetCursor LoadCursor(0, IDC_HAND)
End Sub
Private Sub Option1_MouseOut()
bHovering = False
Label5.Caption = "Mouse not on Option1"
End Sub
Private Sub Option1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
bHovering = True
Label5.Caption = "Mouse is on Option1"
End Sub
Private Sub Command1_MouseOut()
bHovering = False
Label2.Caption = "Mouse not on Command1"
End Sub
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
bHovering = True
Label2.Caption = "Mouse is on Command1"
End Sub
Private Sub Check1_MouseOut()
bHovering = False
Label4.Caption = "Mouse not on Check1"
End Sub
Private Sub Check1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
bHovering = True
Label4.Caption = "Mouse is on Check1"
End Sub
Private Sub Frame1_MouseOut()
bHovering = False
Label3.Caption = "Mouse not on Frame1"
End Sub
Private Sub Frame1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
bHovering = True
Label3.Caption = "Mouse is on Frame1"
End Sub
Private Sub Text1_MouseOut()
bHovering = False
Label6.Caption = "Mouse not on Text1"
End Sub
Private Sub Text1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
bHovering = True
Label6.Caption = "Mouse is on Text1"
End Sub
Private Sub MouseMove_Timer()
Dim lpPos As POINTAPI
Dim lhWnd As Long
GetCursorPos lpPos
lhWnd = WindowFromPoint(lpPos.X, lpPos.Y)
If bHovering = True Then
If lhWnd <> Form1.hwnd Then Form_MouseOut
If lhWnd <> Picture1.hwnd Then Picture1_MouseOut
If lhWnd <> Option1.hwnd Then Option1_MouseOut
If lhWnd <> Command1.hwnd Then Command1_MouseOut
If lhWnd <> Check1.hwnd Then Check1_MouseOut
If lhWnd <> Frame1.hwnd Then Frame1_MouseOut
If lhWnd <> Text1.hwnd Then Text1_MouseOut
End If
End Sub