VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Drag and Drop anywhere on form

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 Declarations
Public X1, Y1

Rate Drag and Drop anywhere on form

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

Download this snippet    Add to My Saved Code

Drag and Drop anywhere on form Comments

No comments have been posted about Drag and Drop anywhere on form. Why not be the first to post a comment about Drag and Drop anywhere on form.

Post your comment

Subject:
Message:
0/1000 characters