Drag, DragMode, DragIcon, DragOver, DragDrop
These properties, events and method allow you to put drag-and-drop with VFP objects in your applications. It's astonishingly easy to get simple drag-and-drop to work, but making it look smooth and elegant is another story. Drag-and-drop with other applications or ActiveX controls uses a collection of properties and methods whose names start with OLEDrag or OLEDrop.
Usage |
oObject.DragMode = nDragMode nDragMode = oObject.DragMode oObject.Drag( [ nDragAction ] ) |
Parameter |
Value |
Meaning |
nDragMode |
0 |
Use manual dragging. |
1 |
Enable automatic dragging. |
|
nDragAction |
0 |
Cancel dragging. |
1 or Omitted |
Start dragging. |
|
2 |
Stop dragging. |
Usage |
oObject.DragIcon = cCursorFile cCursorFile = oObject.DragIcon |
Usage |
PROCEDURE oObject.DragOver LPARAMETERS [ nIndex, ] oSource, nXCoord, nYCoord, nState PROCEDURE oObject.DragDrop LPARAMETERS [ nIndex, ] oSource, nXCoord, nYCoord |
Parameter |
Value |
Meaning |
nIndex |
Numeric |
This object is part of a control array. nIndex is the item number within the array. |
Omitted |
The object is not part of a control array. |
|
oSource |
Object |
A reference to the object being dragged. |
nXCoord, nYCoord |
Numeric |
The mouse coordinates relative to the form when the event fires. |
nState |
0 |
The dragged object is just entering this object's space. |
1 |
The dragged object is now leaving this object's space. |
|
2 |
The dragged object remains over this object's space. |
If an object is small enough, it's possible to drag another object over it without firing the small object's DragOver method. When dragging slowly, DragOver always fires, but if you drag quickly across a narrow object, DragOver may fail to fire. |
If the DragIcon of the source object is set to a cursor file, issuing Drag(0) in the DragOver event of another object is useless. The drag isn't canceled. As long as the DragIcon is the default fuzzy box, Drag(0) works just fine. |
Example |
* This form is included in the Developer Downloads * available at www.hentzenwerke.com as Dragger.SCX. * The object we want to drag is a text box. Put it in the * middle of the form. In the prop sheet: DragIcon = HOME(4) + "CURSORS\DRAGPICT.CUR" * In the text box's MouseDown event: This.Drag(1) This.DragIcon = HOME(4)+"CURSORS\DRAGPICT.CUR" * The form contains 4 other objects: a button, a shape and * two vertical lines. Position one vertical line near the left * edge of the form and put this code in its DragOver: oSource.Drag(0) && Cancel drag * Put the other line near the right edge of the form. * In its DragOver, put: oSource.Drag(2) && End drag * In this line's DragDrop method, put: WAIT WINDOW "Ouch, that hurts!" NOWAIT * Put the button and the shape between the two lines, but not * on top of the text box. In the button's DragOver method, put: DO CASE CASE nState = 0 oSource.DragIcon = HOME(4) + ; "CURSORS\NODROP01.CUR" CASE nState = 1 oSource.DragIcon = HOME(4) +; "CURSORS\DRAGPICT.CUR" ENDCASE * In the shape's DragOver method, put: DO CASE CASE nState = 0 oSource.DragIcon = HOME(4) + ; "CURSORS\BULLSEYE.CUR" CASE nState = 1 oSource.DragIcon = HOME(4) + ; "CURSORS\DRAGPICT.CUR" ENDCASE In the shape's DragDrop method, put: WAIT WINDOW "Right on target!" In the form's DragDrop method, put: oSource.Left = nXCoord oSource.Top = nYCoord |
See Also |
GetPict(), Home(), MouseDown, MouseMove, OLE drag and drop, OLEDrag, OLEDragDrop, OLEDragMode, OLEDragOver, OLEDragPicture |