19-03-14, 04:44 PM
جرب هـذا الكود وبإدن الله سيعجب
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Static CtrMov As Boolean
With Command1 'Change this 'Command1' to your control name
If (X < 0) Or (Y < 0) Or (X > .Width) Or (Y > .Height) Then
ReleaseCapture
CtrMov = False
'Put here your code to LostMouseFocus
'For example:
Me.Print "LostMouseFocus"
Else
SetCapture .hwnd
If CtrMov = False Then
CtrMov = True
'Put here your code to GetMouseFocus
'For example:
Me.Print "GetMouseFocus"
End If
End If
End With
End Sub
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Static CtrMov As Boolean
With Command1 'Change this 'Command1' to your control name
If (X < 0) Or (Y < 0) Or (X > .Width) Or (Y > .Height) Then
ReleaseCapture
CtrMov = False
'Put here your code to LostMouseFocus
'For example:
Me.Print "LostMouseFocus"
Else
SetCapture .hwnd
If CtrMov = False Then
CtrMov = True
'Put here your code to GetMouseFocus
'For example:
Me.Print "GetMouseFocus"
End If
End If
End With
End Sub
على فكرة هذا الكود مأخود من برنامج صغير إسمه بنك الأكواد