VB Code:
  1. Option Explicit
  2.  
  3. Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
  4. Private Declare Function ReleaseCapture Lib "user32" () As Long
  5. Private Declare Function GetCapture Lib "user32" () As Long
  6.  
  7. Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  8.    
  9.     With Command1
  10.         If (X < 0) Or (Y < 0) Or (X > .Width) Or (Y > .Height) Then 'MouseLeave
  11.             Call ReleaseCapture
  12.         ElseIf GetCapture() <> .hwnd Then 'MouseEnter
  13.             Call SetCapture(.hwnd)
  14.         Else
  15.             'Normal MouseMove
  16.         End If
  17.     End With
  18.  
  19. End Sub

Replace Command1 with the name of the control. The control must have an hWnd property, and support the MouseMove event for this to work.