DragDrop Event

See Also1M6R0OJ              ExampleLTQXEW>Low

Applies To

Form14TJ2LN, MDI form1ILMZQ7, check box9P3BU5, combo box1YZXFF6, command buttonXJSPC0, data control2E1FEX3, directory list boxO9U5A0, drive list box5WJO0PW, file list box1M6S8UX, frame1KX6ZP8, grid2VGT0PT, horizontal scroll bar1JSJOS7, image9A4FCA, label3MNIZ8D, list boxG11UCK, OLE control2HQDVVU, option buttonJYBO08, picture box31MYIWX, text boxYPYZDG, vertical scroll bar1JSJOS7.

Description

Occurs when a drag-and-drop operation1MXLXNZ is completed as a result of dragging a control over a form or control and releasing the mouse button; or using the Drag2IEV8PA method with its action argument = 2 (Drop).

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 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 ScaleHeight3J8U7ZN, ScaleWidth3J8U7ZN, ScaleLeft138Z3ME, and ScaleTop138Z3ME 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 IfLANIF statement to determine the type of control used with Source.

         Use the control's Tag6GI6KP property to identify a control, and then use a DragDrop procedure.

 

Note   Use the DragModeS9LGP1 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 DragOver2TUGMAC procedure.

 


See Also

Help:

Drag Method2IEV8PA

DragIcon Property3G3M07O

DragMode PropertyS9LGP1

DragOver Event2TUGMAC

MouseDown, MouseUp EventsD0VNMJ

MouseMove Event1D70SW5

 

Programmer's Guide:

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

   End If

End Sub