Compartir a través de


OLE Drag-and-Drop

Visual FoxPro supports OLE drag-and-drop, a powerful and useful tool that makes it possible for you to move data between other applications that support OLE drag-and-drop (such as Visual FoxPro, Visual Basic, the Windows Explorer, Microsoft Word and Excel, and so on). In a distributed Visual FoxPro application, you can move data between controls in the application or between controls and other Window applications that support OLE drag-and-drop.

Note that previous versions of Visual FoxPro supported a programmatic drag-and-drop feature for controls, making it possible for you to move controls on a form. This form of drag and drop is still supported in Visual FoxPro. However, if you choose to implement drag and drop support in your applications, you should exclusively use either programmatic drag and drop for controls or OLE drag-and-drop – don't mix the two types of drag and drop support.

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

Dragging and Dropping Data

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.

Drag Source Properties, Events, and Methods

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.

Drop Target Properties and Events

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

To cancel the OLE drag-and-drop operation, press ESC during the operation.

See Also

Interoperability and the Internet | Design-Time OLE Drag-and-Drop Support | Run-Time OLE Drag-and-Drop Support | Implementing Intrinsic and Manual OLE Drag-and-Drop Modes | Active Documents