Results 1 to 5 of 5

Thread: Dragging and dropping

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Posts
    221

    Dragging and dropping

    How can i drag something to somewhere else on the form?

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    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:
    1. Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
    2.   Source.Left = X
    3.   Source.Top = Y
    4. 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!
    Like Archer? Check out some Sterling Archer quotes.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Posts
    221

    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?

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Posts
    221

    Re: Dragging and dropping

    can someone help please? and btw, it was an imagebox called "house", not a picture.

  5. #5
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    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:
    1. Private sngDragX As Single
    2. Private sngDragY As Single
    3.  
    4. Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
    5.     Source.Move X - sngDragX, Y - sngDragY
    6. End Sub
    7.  
    8. Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    9.     sngDragX = X: sngDragY = Y
    10.     Image1.Drag vbBeginDrag
    11. 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
  •  



Click Here to Expand Forum to Full Width