How can i make a Drag & Drop in VB
Printable View
How can i make a Drag & Drop in VB
That all depends on what you want to drag and drop in VB. If you want to drag a picture box, you can use this:
VB Code:
'This goes in a module Private Declare Function SendMessage Lib "User32" _ Alias "SendMessageA" (ByVal hWnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ lParam As Any) As Long Private Declare Sub ReleaseCapture Lib "User32" () Const WM_NCLBUTTONDOWN = &HA1 Const HTCAPTION = 2 Add this code To the form's MouseMove procedure: Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Dim lngReturnValue As Long If Button = 1 Then Call ReleaseCapture lngReturnValue = SendMessage(Form1.hWnd, WM_NCLBUTTONDOWN, _ HTCAPTION, 0&) End If End Sub Private Declare Function SendMessage Lib "User32" _ Alias "SendMessageA" (ByVal hWnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ lParam As Any) As Long Private Declare Sub ReleaseCapture Lib "User32" () Const WM_NCLBUTTONDOWN = &HA1 Const HTCAPTION = 2 'Add this code To the form's MouseMove procedure: Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Dim lngReturnValue As Long If Button = 1 Then Call ReleaseCapture lngReturnValue = SendMessage(Picture.hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&) End If End Sub
Or you can set an object's dragmode to Automatic and in the form's dragdrop event, use source.left = x and source.top = y.