Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

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.


advertisement
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.

Argument

Value

Format

0 or omitted

-

Automatic format detection based on the data.

vbCFText

1

Text

vbCFBitmap

2

Bitmap

vbCFMetafile

3

Metafile

vbCFEMetafile

14

Enhanced metafile

vbCFDIB

8

Device-independent bitmap

vbCFPalette

9

Color palette

vbCFFIles

15

List of files

vbCFRTF

-16639

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.

 

 

Sitemap