|
-
Oct 8th, 2006, 07:01 AM
#1
Thread Starter
Addicted Member
Dragging and dropping
How can i drag something to somewhere else on the form?
-
Oct 8th, 2006, 07:48 AM
#2
Re: Dragging and dropping
set the DragMode property on the controls you want to be able to drag and drop to "Automatic," and then for the item that you want to be able to "drag onto," insert something like this into the "DragDrop" or "DragOver" events:
VB Code:
Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
Source.Left = X
Source.Top = Y
End Sub
For the code above, I made a CommandButton have a DragMode of Automatic, and when I ran it, if I dragged the button somewhere on the form its position would move. Very basic example, but it can get you started I suppose!
-
Oct 8th, 2006, 08:46 AM
#3
Thread Starter
Addicted Member
Re: Dragging and dropping
yeah, i done that with my picture (it was a picture i used btw) and it worked and moved for me but then it jumped places a bit and i've found out that's cause my mouse wasn't in the very top corner. How do i make it so it doesn't jump down?
-
Oct 8th, 2006, 09:30 AM
#4
Thread Starter
Addicted Member
Re: Dragging and dropping
can someone help please? and btw, it was an imagebox called "house", not a picture.
-
Oct 8th, 2006, 10:01 AM
#5
Re: Dragging and dropping
Save the mouse coordinates (MouseDown event) when the drag operation begins. Adjust the X, Y coordinates of the DragDrop event.
You will need to set the DragMode property back to Manual as the Mouse events are not fired when DragMode is Automatic.
The following works fine if the Image control is on the Form and you are dropping it on the Form.
VB Code:
Private sngDragX As Single
Private sngDragY As Single
Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
Source.Move X - sngDragX, Y - sngDragY
End Sub
Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
sngDragX = X: sngDragY = Y
Image1.Drag vbBeginDrag
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|