Search Tools Links Login

Drag and Drop anywhere on form


Visual Basic 6, or VB Classic

Use this code to drag and drop any control anywhere on a form or another control.

Original Author: Michael Frey

Assumptions

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

Code

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

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 117 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.