See Also Example
Form, MDI form, check box , combo box , command button , data control , directory list box , drive list box , file list box , frame , grid , horizontal scroll bar , image , label , list box , OLE control , option button , picture box , text box , vertical scroll bar .
Occurs when a drag-and-drop operation is completed as a result of dragging a control over a form or control and releasing the mouse button; or using the Drag method with its action argument = 2 (Drop).
Sub Form_DragDrop (Source As Control, X As Single, Y As Single)
Sub MDIForm_DragDrop (Source As Control, X As Single, Y As Single)
Sub ctlname_DragDrop ([Index As Integer,]Source As Control, X As Single, Y As Single)
The DragDrop event uses these arguments:
Index Uniquely identifies a control if it is in a control array8G7Y0UU.
Source The control being dragged. You can refer to properties and methods with this argumentfor example, Source.Visible = 0.
X, Y The current horizontal (X) and vertical (Y) position of the mouse pointer within the target form or control. These coordinates are always expressed in terms of the target's coordinate system as set by the ScaleHeight , ScaleWidth , ScaleLeft , and ScaleTop properties.
Use a DragDrop event procedure to control what happens after a drag operation has been completed. For example, you can move the source control to a new location or copy a file from one location to another.
When multiple controls can potentially be used in a Source argument:
Use the TypeOf reserved word with the If statement to determine the type of control used with Source.
Use the control's Tag property to identify a control, and then use a DragDrop procedure.
Note Use the DragMode property and Drag method to specify the way dragging is initiated. Once dragging has been initiated, you can handle events that precede a DragDrop event with a DragOver procedure.
MouseDown, MouseUp Events
Chapter 12, "Responding to Mouse Events"
DragDrop Event Example
The example demonstrates the visual effect of dropping a picture box onto another picture box. To try this example, paste the code into the Declarations section of a form that contains three picture box controls. Set the DragMode property for Picture1 and Picture2 to 1 (Automatic) Use the Picture property to assign bitmaps to Picture1 and Picture2. Then press F5 and drag Picture1 or Picture2 over Picture3..
Sub Picture3_DragDrop (Source As Control, X as Single, Y As Single)
If TypeOf Source Is PictureBox Then
' Set Picture3 bitmap to same as source control.
Picture3.Picture = Source.Picture