DragOver Event

See AlsoG1SBXW              ExampleWXGZEW>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.


Occurs when a drag-and-drop operation1MXLXNZ is in progress.  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.


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)


The DragOver 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 = 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 ScaleHeight3J8U7ZN, ScaleWidth3J8U7ZN, ScaleLeft138Z3ME, and ScaleTop138Z3ME 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 BackColor1W9T6JQ or ForeColor1W9T6JQ property from code) or by displaying a special drag pointer (set the DragIcon3G3M07O or MousePointer1VSV6UM 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 DragModeS9LGP1 property and Drag2IEV8PA method to specify the way dragging is initiated.  For suggested techniques with the Source argument, see the Remarks for the DragDrop1EBOJGL Event topic.


See Also


Drag Method2IEV8PA

DragDrop Event1EBOJGL

DragIcon Property3G3M07O

DragMode PropertyS9LGP1

MouseDown, MouseUp EventsD0VNMJ

MouseMove Event1D70SW5


Programmer's Guide:

Chapter 12, "Responding to Mouse Events"

DragOver Event Example

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