Drag and Drop anywhere on form
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 Declarations
Public X1, Y1
Rate Drag and Drop anywhere on form
(5(5 Vote))
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
Drag and Drop anywhere on form Comments
No comments yet — be the first to post one!
Post a Comment