Visual Basic Reference

DragDrop Event

See Also    Example    Applies To

Occurs when a drag-and-drop operation is completed as a result of dragging a control over an object and releasing the mouse button or using the Drag method with its action argument set to 2 (Drop).

Syntax

Private SubForm_DragDrop(sourceAsControl, xAsSingle, yAsSingle)

Private SubMDIForm_DragDrop(sourceAsControl, xAsSingle, yAsSingle)

Private Subobject_DragDrop([indexAsInteger,]sourceAsControl, xAsSingle, yAsSingle)

The DragDrop event syntax has these parts:

Part Description
object An object expression that evaluates to an object in the Applies To list.
index An integer that uniquely identifies a control if it's in a control array.
source The control being dragged. You can include properties and methods in the event procedure with this argument for example, Source.Visible = 0.
x, y A number that specifies 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.

Remarks

Use a DragDrop event procedure to control what happens after a drag operation is 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 keyword 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 event 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 event procedure.