

Program OLEDrag2 uses this method to handle more data types than the previous example. The program can then use the DataObject’s GetData method to retrieve the data. For example, a PictureBox can verify that the data is a bitmap. The program should examine this object to see if the data comes in a format that the control can understand. When something is dropped on the control, its OLEDragDrop even handler receives a reference to a DataObject object that describes the data available from the drag source. To gain greater control over the OLE drag and drop process, set the drop destination control’s OLEDropMode property to 1 – Manual. Click and drag pictures from other applications into the bottom PictureBoxes. The program contains no Visual Basic code whatsoever.Ĭlick and drag pictures from the top set of PictureBoxes into the bottom set or into other applications that can draw pictures. The OLEDropMode properties of the picDragTo controls at the bottom are set to 2 – Automatic. The OLEDragMode properties of the picDragFrom controls at the top are set to 0 – Automatic. Program OLEDrag1 uses this technique to drag and drop images. In that case, you are done! Visual Basic and the Windows operating system automatically handle all of the details of dragging and dropping. The easiest way to make a control accept OLE drops is to set its OLEDropMode property to 2 – Automatic. You can also start a drag programmatically using the OLEDrag method, much as you can start a normal drag using a control’s Drag method. You can allow a control to be the source of an OLE drag by setting its OLDDragMode property to 0 – Automatic. The programs communicate behind the scenes using Object Linking and Embedding (OLE) so this technique is called OLE drag and drop.

The source and destination applications must perform some negotiation to make the drag and drop work. OLE Drag & Drop Allowing a program to drag and drop with other applications is a little more complicated.

This week you’ll see what happens when objects are dragged from one application to another. Last week you learned how to respond when files are dragged onto a program’s icon, when objects are dragged within a single program. You can drag files to and from Windows Explorer, the desktop, folders, and icons and shortcuts representing other applications, and while it’s common throughout Windows applications in general, it’s rare in Visual Basic programs. As I said last week in Part I, drag and drop is everywhere in the Windows operating environment.
