Compartir a través de


Dragging and Dropping Data

Understanding some of the basics of OLE drag-and-drop applications makes it easier to take full advantage of their features.

The mouse is used to drag and drop data between applications and controls. For example, you can select a set of files in the Windows Explorer. You can then press and hold the mouse button down while dragging the files, then release the mouse button to drop them onto the Visual FoxPro Project Manager, or you can select text in a Word document and drop the text into a text box on a Visual FoxPro form. During the OLE drag-and-drop operation, the mouse cursor changes to indicate that an OLE drag-and-drop operation is in effect.

Drag Source

The application or control from which data is moved is called the drag source.

The following table lists the properties, events, and methods available for an OLE drag source.

Property, Event, or Method

Description

OLECompleteDrag Event

Occurs when data is dropped on the drop target or the OLE drag-and-drop operation is canceled.

OLEDrag Method

Starts an OLE drag-and-drop operation.

OLEDragPicture Property

Specifies the picture displayed under the mouse pointer during an OLE drag-and-drop operation. You can specify a picture file of type .bmp, .dib, .jpg, .gif, .ani, .cur, and .ico.

OLEDragMode Property

Specifies how a drag source manages OLE drag operations.

OLEGiveFeedBack Event

Occurs after every OLEDragOver event. Allows the drag source to specify the type of OLE drag-and-drop operation and the visual feedback.

OLESetData Event

Occurs when a drop target calls the GetData method and there is no data in a specified format on the OLE drag-and-drop DataObject.

OLEStartDrag Event

Occurs when the OLEDrag method is called.

Drop Target

The application or control to which the data is moved is called the drop target.

The following table lists the properties, events, and methods available for an OLE drop target.

Property or Event

Description

OLEDragDrop Event

Occurs when data is dropped on a drop target and the drop target's OLEDropMode property is set to 1 – Enabled.

OLEDragOver Event

Occurs when data is dragged over a drop target and the drop target's OLEDropMode property is set to 1 – Enabled.

OLEDropEffects Property

Specifies the type of drop operations an OLE drop target supports.

OLEDropHasData Property

Specifies how a drop operation is managed.

OLEDropMode Property

Specifies how a drop target manages OLE drop operations.

Moving Data

To perform a drag-and-drop operation to move data using the default (left) mouse button, select the data you want to move in the drag source. After selecting the data, press and hold down the mouse button as you move the mouse pointer over the drop target. Release the mouse button to drop the data onto the drop target. During the OLE drag-and-drop operation, the mouse cursor changes to indicate that an OLE drag-and-drop operation is in effect.

You can also click the non-default (right) mouse button on the data in a drag source and drag it to a drop target. Depending on the drop target, a context menu may be displayed when you drop the data on the drop target. The context menu contains a set of options that make it possible for you to choose how the data is processed by the drop target.

Copying Data

You can also copy data from a drag source and paste it in a drop target. Press the Ctrl key as you click the mouse on the data selected in the drag source. The mouse cursor displays a plus sign (+) while the mouse is dragged to indicate a Copy operation is in effect.

Targets and Sources Not Supporting OLE drag-and-drop

You can only move or copy data from a drag source that supports OLE drag-and-drop, and the drop target must also support OLE drag-and-drop. Note that while a drop target may support OLE drag-and-drop, the drop target doesn't have to accept the data you attempt to drop on it. For example, the data you're moving or copying may be in a format the drop target doesn't support. During a drag-and-drop operation, the mouse cursor changes to a No Drop symbol (a slashed circle) to indicate the mouse is positioned over an area of an application or control where the data cannot be dropped.

Canceling an Operation

You can cancel the OLE drag-and-drop operation by pressing ESC during the operation.

See Also

Reference

OLE Drag-and-Drop

Run-Time OLE Drag-and-Drop Support

Other Resources

Interoperability and the Internet