|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
Copying Pictures To And Pasting Pictures From The ClipboardThe 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, well paste a picture from Picture1 to Picture2 using two buttons, Command1 and Command2. When the user clicks Command1, well copy the picture from Picture1 to the Clipboard; when the user clicks Command2, well 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:
If you omit the format parameter, Visual Basic will determine the correct format, so well 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 dont 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
Thats all it takeswhen 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 were using the Clipboard with picture boxes. Printing GraphicsVisual Basic has two ways of printing both text and graphics:
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 forms 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 weve 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.
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. Lets 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.
|
|
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. |