Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, _
X As Single, Y As Single) 'See if the mouse is over the PictureBox. If X < 0 Or X > Picture1.Width Or _ Y < 0 Or Y > Picture1.Height Then 'The mouse is not over the PictureBox Release the capture. ReleaseCapture Picture1.BorderStyle = vbBSNone m_MouseCaptured = False Else 'The mouse is over the PictureBox. 'See if we already have the mouse captured. If Not m_MouseCaptured Then 'The mouse is not captured. Capture it. m_MouseCaptured = True SetCapture Picture1.hwnd Picture1.BorderStyle = vbFixedSingle End If End If End Sub Private Sub Picture1_Click() 'Release the capture. Picture1_MouseMove 0, 0, -1, -1 'Click. MsgBox "Clicked" End Sub Note that Windows sets and releases capture when you click on the button. The program should set is m_MouseCaptured flag to False when this happens so it knows the mouse is not captured |