Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Visual Basic 6 Black Book
(Publisher: The Coriolis Group)
Author(s): Steven Holzner
ISBN: 1576102831
Publication Date: 08/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


Copying Pictures To And Pasting Pictures From The Clipboard

The users love your new graphics program, SuperDuperGraphicsPro, but would like to export the images they create to other programs. How can you do that?

You can copy the images to the Clipboard, letting the user paste them into other programs. To place data in the Clipboard, you use SetData, and to retrieve data from the Clipboard, you use GetData.

An example will make this clearer. Here, we’ll paste a picture from Picture1 to Picture2 using two buttons, Command1 and Command2. When the user clicks Command1, we’ll copy the picture from Picture1 to the Clipboard; when the user clicks Command2, we’ll paste the picture to Picture2.

To place the image in Picture1 into the Clipboard, we use SetData:

Clipboard.SetData   data, [format]

Here are the possible values for the format parameter for images:

  vbCFBitmap—2; bitmap (BMP) files
  vbCFMetafile—3; metafile (WMF) files
  vbCFDIB—8; device-independent bitmap (DIB)
  vbCFPalette—9; color palette

If you omit the format parameter, Visual Basic will determine the correct format, so we’ll just copy the picture from Picture1.Picture to the Clipboard this way:

Private Sub Command1_Click()
    Clipboard.SetData Picture1.Picture
End Sub

To paste the picture, use GetData():

Clipboard.GetData ([  format])

The format parameter here is the same as for SetData(), and as before, if you don’t specify the format, Visual Basic will determine it, so when the user clicks the second button, we paste the image into Picture2 this way:

Private Sub Command2_Click()
    Picture2.Picture = Clipboard.GetData()
End Sub

That’s all it takes—when you run the program and click the Copy and then the Paste button, the image is copied to the Clipboard and then pasted into the second picture box. Now we’re using the Clipboard with picture boxes.

Printing Graphics

Visual Basic has two ways of printing both text and graphics:

  Printing entire forms using the PrintForm method
  Printing with the Printer object and using graphical methods as well as the NewPage and EndDoc methods

The PrintForm Method

The PrintForm method sends an image of a given form to the printer, complete with menu bar, title bar, and so on. To print information from your application with PrintForm, you must first display that information on a form and then print that form with the PrintForm method like this:

[form.]PrintForm

If you omit the form name, Visual Basic prints the current form. Note that if a form contains graphics, those graphics print only if the form’s AutoRedraw property is set to True.

The Printer Object

The Printer object represents the default printer and supports text and graphics methods like Print, PSet, Line, PaintPicture, and Circle. You use these methods on the Printer object just as you would on a form or picture box. The Printer object also has all the font properties we’ve seen earlier in this chapter.

When you finish placing the information on the Printer object, you use the EndDoc method to send the output to the printer. You can also print multiple-page documents by using the NewPage method on the Printer object.


TIP:  When applications close, they automatically use the EndDoc method to send any pending information on the Printer object.

The Printers Collection

The Printers collection is an object that contains all the printers that are available, and each printer in the collection has a unique (0-based) index for identification. Let’s see an example. Here, we select the first printer from the Printers collection to be the current printer by loading that printer into the Printer object:

Private Sub Command1_Click()
    Set Printer = Printers(0)
End Sub

Using the Printers collection in this way lets you print to printers other than the default.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.