How to Move Controls at Run Time By Using Drag and DropID: Q103062
|
You can move controls at run time by using manual dragging with the Drag method. Automatic dragging (DragMode = 1) does not work well for repositioning controls at run time.
The key points to remember when using drag and drop to move controls at run
time are:
Dim Save_X As Single
Dim Save_Y As Single
' Enter the following Sub as one, single line:
Sub Picture1_MouseDown (Button As Integer, Shift As Integer, X As
Single, Y As Single)
Save_X = X ' save mouse position (relative to this control)
Save_Y = Y
Picture1.Drag 1 ' begin dragging
End Sub
' Enter the following Sub as one, single line:
Sub Picture1_MouseUp (Button As Integer, Shift As Integer, X As
Single, Y As Single)
Picture1.Drag 2 ' end dragging, do DragDrop event
End Sub
Sub Form_DragDrop (Source As Control, X As Single, Y As Single)
' Move the control to the position of the mouse pointer.
' Adjust it by the distance the mouse pointer to the upper
' left corner of the control.
Source.Move X - Save_X, Y - Save_Y
End Sub
Sub Picture1_DragDrop (Source As Control, X As Single, Y As Single)
' This handles the case when the control is dropped on itself
' as would happen if it was only moved a small amount.
' This is similar to Form_DragDrop except that the X and Y
' parameters are relative to this control, not the form.
Source.Move Picture1.Left + X - Save_X, Picture1.Top + Y - Save_Y
End Sub
Additional query words: 1.00 2.00 3.00 runtime run-time
Keywords :
Version :
Platform :
Issue type :
Last Reviewed: June 21, 1999