|
|
|
Click here to copy the following block | Private Type POINTAPI X As Long Y As Long End Type
Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type
Private Declare Function ClipCursor Lib "user32" (lpRect As RECT) As Long Private Declare Function ClipCursorByNum Lib "user32" Alias "ClipCursor" (ByVal _ lpRect As Long) As Long Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As _ Integer Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, _ lpRect As RECT) As Long Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, _ lpPoint As POINTAPI) As Long Private Declare Function InvalidateRect Lib "user32" (ByVal hwnd As Long, _ lpRect As RECT, ByVal bErase As Long) As Long Private Declare Function InvalidateRectByNum Lib "user32" Alias _ "InvalidateRect" (ByVal hwnd As Long, ByVal lpRect As Long, _ ByVal bErase As Long) As Long
Sub DragControl(ctrl As Control) Dim startButton As Integer Dim startPoint As POINTAPI Dim currPoint As POINTAPI Dim contRect As RECT Dim contScaleMode As Integer GetCursorPos startPoint If GetAsyncKeyState(vbLeftButton) Then startButton = vbLeftButton If GetAsyncKeyState(vbRightButton) Then startButton = startButton Or _ vbRightButton If GetAsyncKeyState(vbMiddleButton) Then startButton = startButton Or _ vbMiddleButton ClientToScreen ctrl.Container.hwnd, currPoint GetClientRect ctrl.Container.hwnd, contRect contRect.Left = currPoint.X contRect.Top = currPoint.Y contRect.Right = contRect.Right + currPoint.X contRect.Bottom = contRect.Bottom + currPoint.Y ClipCursor contRect On Error Resume Next contScaleMode = vbTwips contScaleMode = ctrl.Container.ScaleMode Do If (startButton And vbLeftButton) = 0 Or GetAsyncKeyState(vbLeftButton) _ = 0 Then If (startButton And vbRightButton) = 0 Or GetAsyncKeyState _ (vbRightButton) = 0 Then If (startButton And vbMiddleButton) = 0 Or GetAsyncKeyState _ (vbMiddleButton) = 0 Then Exit Do End If End If End If GetCursorPos currPoint If currPoint.X <> startPoint.X Or currPoint.Y <> startPoint.Y Then With ctrl.Parent ctrl.Move ctrl.Left + .ScaleX(currPoint.X - startPoint.X, _ vbPixels, contScaleMode), ctrl.Top + .ScaleY(currPoint.Y - _ startPoint.Y, vbPixels, contScaleMode) InvalidateRectByNum .hwnd, 0, False .Refresh End With LSet startPoint = currPoint End If DoEvents Loop ClipCursorByNum 0 End Sub |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|