DragOver Event Example
This example demonstrates one way to indicate a valid drop target. The pointer changes from the default arrow to a special icon when a TextBox control is dragged over a PictureBox control. The pointer returns to the default when the source is dragged elsewhere. To try this example, paste the code into the Declarations section of a form that contains a small TextBox and a PictureBox. Set the TextBox control's DragMode property to 1, and then press F5 and drag the TextBox over the PictureBox.
Private Sub Picture1_DragOver (Source As Control, X As Single, Y As Single, State As Integer)
Select Case State
Case vbEnter
' Load icon.
Source.DragIcon = LoadPicture("ICONS\ARROWS\POINT03.ICO")
Case vbLeave
Source.DragIcon = LoadPicture() ' Unload icon.
End Select
End Sub
Private Sub Picture1_DragDrop (Source As Control, X As Single, Y As Single)
Source.DragIcon = LoadPicture() ' Unload icon.
End Sub
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 Sub Form_DragDrop(source As Control, x As Single, y As Single)
Private Sub MDIForm_DragDrop(source As Control, x As Single, y As Single)
Private Sub object_DragDrop([index As Integer,]source As Control, x As Single, y As Single)
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.
--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources.
DragDrop Event Example
This example demonstrates the visual effect of dropping a PictureBox control onto another PictureBox control. To try this example, paste the code into the Declarations section of a form that contains three PictureBox controls. Set the DragMode property for Picture1 and Picture2 to 1 (Automatic). Use the Picture property to assign bitmaps to Picture1 and Picture2, and then press F5 and drag Picture1 or Picture2 over Picture3.
Private 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