See Also Example
Applies To
Form, MDI form
Description
Occurs when a drag-and-drop operation
Syntax
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)
Remarks
The DragDrop event uses these arguments:
Argument Description
Index Uniquely identifies a control if it is in a control array .
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.
Help:
Drag Method
DragIcon Property
DragMode Property
DragOver Event
MouseDown, MouseUp Events
MouseMove Event
Programmer's Guide:
Chapter 12, "Responding to Mouse Events"
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
End If
End Sub