by Michael Frey (4 Submissions)
Category: Miscellaneous
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating:
(5 Votes)
Use this code to drag and drop any control anywhere on a form or another control.
Assumes
Lets supose you want to drop a picture or a button on the form or on a big label. Add a Commandbutton (Command1) a big Label (Label1) and a picture (Picture1).
IMPORTANT
The picture and commandbutton property DRAGMODE have to be set to Automatic
API DeclarationsPublic X1, Y1
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
X1 = X
Y1 = Y
End Sub
Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
Source.Top = Y - Y1
Source.Left = X - X1
End Sub
Private Sub Label1_DragDrop(Source As Control, X As Single, Y As Single)
Source.Top = Label1.Top + Y - Y1
Source.Left = Label1.Left + X - X1
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
X1 = X
Y1 = Y
End Sub