Option Explicit
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private m_fCaptured As Boolean
Private Sub TreeView1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim obj As TreeView
Set obj = TreeView1
If m_fCaptured Then
With obj
If x < 0 Or y < 0 Or x > .Width Or y > .Height Then
Debug.Print "out"
ReleaseCapture
m_fCaptured = False
End If
End With
Else
SetCapture obj.hwnd
m_fCaptured = True
End If
End Sub