|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
You can flip a bitmap horizontally or vertically by using negative values for the destination height (height1) and/or the destination width (width1). For example, heres how we flip the image in Picture1 horizontally and display it in Picture2 (keep in mind that to draw from the Form_Load event, you have to set the forms AutoRedraw property to True):
Private Sub Form_Load()
Picture2.PaintPicture Picture1.Picture, Picture1.ScaleWidth, 0, _
-1 * Picture1.ScaleWidth, Picture1.ScaleHeight
Picture2.Height = Picture1.Height
End Sub
The results of the preceding code appear in Figure 10.14. Now were flipping images in picture boxes.
Printing A PictureCan you print the image in a picture box out on the printer? You sure can, using the PaintPicture method. To print on the printer, you just use the Visual Basic Printer object this way with PaintPicture:
Printer.PaintPicture picture, x1, y1, [width1, height1, [x2, y2, _
[width2, height2, [opcode]]]]
Heres what the arguments passed to PaintPicture mean:
For example, heres how to print the picture in Picture1 on the printer:
Private Sub Command1_Click()
Printer.PaintPicture Picture1.Picture, 0, 0
End Sub
Thats all there is to itthe PaintPicture method is extraordinarily powerful. Note that before printing a picture, you may want to display a Print dialog box (see the next chapter). Using Picture Box HandlesYou can gain even more control over whats going on in a picture box by using the various Windows handles available for that control together with direct Windows API calls. Here are the picture box handle properties:
For example, here we use the hDC property of a picture box to create a compatible bitmap and device context matching the picture box, using the Windows API functions CreateCompatibleDC() and CreateCompatibleBitmap() (these and all Windows API functions must also be declared in the program, as well see in Chapter 23):
Private Sub Form_Load()
Picture1.Picture = LoadPicture("image.bmp")
Dim dcMemory As Long
Dim hMemoryBitmap As Long
dcMemory = CreateCompatibleDC(Picture1.hdc)
hMemoryBitmap = CreateCompatibleBitmap(Picture1.hdc, 60, 30)
End Sub
Setting Measurement Scales In A Picture BoxPicture boxes have a number of scale properties, and perhaps the most popular one is ScaleMode, which sets the units of measurement in a picture box. Here are the possible values for ScaleMode (note that when you set the scale mode of a picture box, all measurements are in those new units, including coordinates passed to your program, like mouse-down locations):
For example, in our image map example, we set the scale mode to pixels:
Private Sub Form_Load()
Picture1.ScaleMode = vbPixels
End Sub
|
|
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. |