See Also Example
Applies To
Form, MDI form
Description
Occurs when a drag-and-drop operation You can use this event to monitor when the mouse pointer enters, leaves, or is directly over a valid target. The mouse pointer position determines which target object receives this event.
Syntax
Sub Form_DragOver (Source As Control, X As Single, Y As Single, State As Integer)
Sub MDIForm_DragOver (Source As Control, X As Single, Y As Single, State As Integer)
Sub ctlname_DragOver ([Index As Integer,]Source As Control, X As Single, Y As Single, State As Integer)
Remarks
The DragOver 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 = False.
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.
State The transition state of the control being dragged in relation to a target form or control:
0 - Enter (source control is being dragged within the range of a target).
1 - Leave (source control is being dragged out of the range of a target).
2 - Over (source control has moved from one position in the target to another).
Use a DragOver event procedure to determine what happens after dragging is initiated and before a control drops onto a target. For example, you might verify a valid target range by highlighting the target (set the BackColor or ForeColor property from code) or by displaying a special drag pointer (set the DragIcon or MousePointer property from code).
Use the argument State to determine actions at key transition points. For example, you might highlight a possible target on State 0 (Enter) and restore the object's previous appearance on State 1 (Leave).
When an object receives a DragOver event with State = 0 (Enter):
If the source control is dropped on a valid target, a DragDrop event is generated.
If the source control is not dropped on a valid target, another DragOver event is generated with State = 1 (Leave).
Note Use the DragMode property and Drag method to specify the way dragging is initiated. For suggested techniques with the Source argument, see the Remarks for the DragDrop Event topic.
Help:
Drag Method
DragDrop Event
DragIcon Property
DragMode Property
MouseDown, MouseUp Events
MouseMove Event
Programmer's Guide:
Chapter 12, "Responding to Mouse Events"
The example demonstrates one way to indicate a valid drop target. The drag pointer changes from the default arrow to a special icon when a text box is dragged over a picture box. The drag 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 text box and a picture box. Set the text box DragMode property to 1. Then press F5 and drag the text box over the picture box.
Sub Picture1_DragOver (Source As Control, X As Single, Y As Single, State As Integer)
Const ENTER = 0 ' Define constants.
Const LEAVE = 1
Select Case State
Case ENTER
' Load icon.
Source.DragIcon = LoadPicture("ICONS\ARROWS\POINT03.ICO")
Case LEAVE
Source.DragIcon = LoadPicture() ' Unload icon.
End Select
End Sub
Sub Picture1_DragDrop (Source As Control, X As Single, Y As Single)
Source.DragIcon = LoadPicture() ' Unload icon.
End Sub