|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
Then we could use pixel dimensions in the MouseDown event:
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As _
Single, Y As Single)
If X > 16 And X < 83 And Y > 11 And Y < 36 Then
MsgBox "You clicked the word ""Picture"""
End If
If X > 83 And X < 125 And Y > 11 And Y < 36 Then
MsgBox "You clicked the word ""Box"""
End If
End Sub
If you set the scale mode to vbUser, you can define your own units by setting the dimensions of the picture box using the ScaleLeft, ScaleTop, ScaleWidth, and ScaleHeight properties. This can be very useful if youre plotting points and want to use a picture box as a graph.
Saving Pictures To DiskWe already know you can load pictures into a picture box with the LoadPicture function. Can you save them to disk? Yes, you can, using SavePicture. Heres how that statement works: SavePicture picture, stringexpression Heres what the parameters for SavePicture mean:
SavePicture only saves images in BMP, WMF, and ICO formats (depending on the file type the image came from originally); if the image came from a GIF or JPEG file, its saved in BMP format. Graphics in an Image property are always saved as bitmap (.bmp) files no matter what their original format. Heres an example where we save the image from Picture1 to a file, C:\image.bmp, when the user clicks a button:
Private Sub Command1_Click()
SavePicture Picture1.Picture, "c:\image.bmp"
End Sub
Adding An Image Control To A FormYouve got 200 picture boxes in your program, and suddenly the Testing Department is on the line: your program is causing users computers to run out of memory. No problem here, you say. They say, thats because not everyone has 128MB of RAM like you doits time to decrease your programs memory consumption. One way of using fewer system resources is to use fewer picture boxes. As weve seen in this chapter, picture boxes are powerful controlsand with that power comes lots of overhead. If youre just going to be displaying images, use image controls instead. The image control uses fewer system resources and repaints faster than a picture box (however, it supports only a subset of the picture box properties, events, and methods). To install an image control, just use the Image Control tool in the toolbox. After adding the image control to your form, just set its Picture property to the image file you want to display. By default, image controls shape themselves to the image you display; if you want to stretch the image to fit the image control and not the other way around, set the image controls Stretch property to True (the default is False). As an example, weve placed an (unstretched) image in the image control in Figure 10.15.
Stretching An Image In An Image ControlYou can stretch (or flip) an image in a picture box using the PaintPicture method, but you cant use PaintPicture with image controls. Is there still some way of producing interesting graphics effects in an image control? You can use the image controls Stretch property. By default, image controls shape themselves to fit the images inside them (after all, their primary purpose is to display images), but if you set the Stretch property to True (the default is False), the image control will stretch the image to fit the control. As an example, were stretching an image in the image control in Figure 10.16.
You can also stretch an image in an image control by resizing the control (using its Width and Height properties) at runtime as long as the controls Stretch property is True.
|
|
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. |