Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Using OLE Drag-and-Drop in Visual Basic 6 : Page 3

There are two types of Drag-and-Drop functionality in Visual Basic: the traditional kind and OLE. This second type of drag-and-drop allows users to drag data between applications as well as within an application. However, it only works with applications that support it. Luckily, this includes most Microsoft applications and many programs from other vendors as well. In this article, learn how to use this basic but essential functionality.




Application Security Testing: An Integral Part of DevOps

Playing Around with OLE
Now you are ready to do some experimenting. Open a picture in the graphics program, select it, and drag it to one of the Picture Box controls in the Visual Basic program. You'll see that the image is moved to the Picture Box. If you hold down the Ctrl key while dragging the picture will be copied rather than moved. You can also drag the picture from one Picture Box to the other. You cannot, however, drag a picture to the Text Box. To experiment with non-image data, launch your word processor and select some text. You'll be able to drag the text to both the Text Box and the Picture Box on your form.

As you have seen, automatic OLE drag-and-drop is quite easy to implement, requiring only that you set a couple of control properties. Simplicity is often accompanied by lack of flexibility, and that's the case here too. Automatic OLE drag-and-drop is undoubtedly more limited than what you can accomplish with manual control.

You need to understand the DataObject class to use manual OLE drag-and-drop. During an OLE drag-and-drop operation, this class is used to store data and information about the data's format. Most of the OLE drag-and-drop related event procedures have an argument that references the DataObject object that is part of the current operation. In the event procedures, you use the object's methods to manage the data.

The DataObject class has four methods. The Clear() method removes all data and other information from the DataObject object. The GetData(format) method returns the data from a DataObject object as a type Variant. The format argument is a constant that specifies the format of the data, as shown in Table 3. If you omit the format argument or pass a value of 0, the method will attempt to determine the best format for the data.

Table 3. Format argument values for the GetData method.




0 or omitted


Automatic format detection based on the data.












Enhanced metafile



Device-independent bitmap



Color palette



List of files



Rich text format.

The SetData method inserts data into a DataObject object using a specified format. The syntax is:

SetData data, format

Both arguments are optional (although you must use at least one). Data is a type Variant containing the data to insert, and format is a constant (from Table 3) specifying the format of the data. If you specify the data argument but not format, Visual Basic will try to determine the format by examining the data. If you specify format without data, the specified format is added to the list of formats the existing data is available in.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date