Visual Basic Reference
Occurs when a drag-and-drop operation is in progress. You can use this event to monitor the mouse pointer as it enters, leaves, or rests directly over a valid target. The mouse pointer position determines the target object that receives this event.
Private Sub Form_DragOver(source As Control, x As Single, y As Single, state As Integer)
Private Sub MDIForm_DragOver(source As Control, x As Single, y As Single, state As Integer)
Private Sub object_DragOver([index As Integer,]source As Control, x As Single, y As Single, state As Integer)
The DragOver event syntax has these parts:
|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 refer to properties and methods in the event procedure with this argument for example, |
|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.|
|state||An integer that corresponds to 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 can 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 state argument to determine actions at key transition points. For example, you might highlight a possible target when state is set to 0 (Enter) and restore the object's previous appearance when state is set to 1 (Leave).
When an object receives a DragOver event while state is set to 0 (Enter):
- If the source control is dropped on the object, that object receives a DragDrop event.
- If the source control isn't dropped on the object, that object receives another DragOver event when state is set to 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 Remarks for the DragDrop event topic.