![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!
Try decreasing the form size; youll notice the circles are not redrawn. Why is this? The Paint event is triggered when an objects size is increased or when it is uncovered; it is not triggered when an objects size decreases. The Picture Box ControlNow lets look at Visual Basics most versatile graphics control: the Picture Box. The capabilities of this control fall into three areas:
The third category doesnt relate to graphics, so we wont discuss it further. The other two, while easy to describe, provide a wealth of graphical capabilities limited only by your imagination. Note that most of the graphics actions that apply to the Picture Box control can also be used with the Form object, which well cover later in the chapter. Lets see how the Picture Box works.
Loading A Picture During Program DesignYou can load a picture into a Picture Box during program design, with the effect of embedding the picture into the projects executable file. (Pictures are often stored as FRX files.) This method is appropriate if a Picture Box will always display the same picture or if you dont want the separate picture file to be distributed with the program. Loading a picture during program design does not prevent you from loading another image into the Picture Box while the program is running. You can load into a Picture Box the image formats shown in Table 12.3. To load a picture at design time, select the Picture Boxs Picture property in the Properties window. Visual Basic displays an Open dialog box, which allows you to select the picture file. The picture you select is displayed in the control during design, as well as when the program runs.
A picture is loaded into a Picture Box control with the top-left corner of the picture positioned in the top-left corner of the Picture Box. If the image is smaller than the Picture Box, the area outside the image displays the color specified by the Picture Boxs BackColor property. If the image is bigger than the control, the portion outside the Picture Box is clipped if the AutoSize property is set to False (the default). You can set the Picture Boxs AutoSize property to True, which causes the Picture Box to automatically grow or shrink to fit the image exactly. You can also load a picture into a Picture Box from the Windows Clipboard. Open the image in the application in which you created or edited it, then copy the image to the Clipboard using the Edit|Copy command. Switch back to Visual Basic, select the Picture Box control, and select Edit|Paste. Loading A Picture During Program ExecutionSeveral methods are available for displaying a picture in a Picture Box at runtime. One method is to set the controls Picture property. You cannot do it directly, as you might expect: Pbox.Picture = filename Does not work! Rather, you must use the LoadPicture function Pbox.Picture = LoadPicture(filename) in which filename is the name of a file in one of the supported image formats, including the full path, if necessary. The position of the picture and the effect of the controls AutoSize property are the same as when you load a picture at design time. You can erase a Picture Box by using LoadPicture with no argument: Pbox.Picture = LoadPicture() You can also copy a picture from one Picture Box to another by accessing the source controls Picture property: Pbox1.Picture = Pbox2.Picture Loading an image into a Picture Box with these methods is fine for most situations, but it does have a few limitations:
Fear not, you do have alternatives. The PaintPicture method, which well discuss next, is one of them. The PaintPicture MethodThe PaintPicture method allows you to circumvent the limitations of the previous methods used to load a picture during program execution. Think of PaintPicture as a sophisticated cut-and-paste tool. You must start with a source picture, which can be an image in either a Picture Box control or on a form. Then you can take all or part of that pictureany rectangular region, in factand place it anywhere you desire on another Picture Box or form, or on the source Picture Box or form. You have numerous options as to how the copied image is combined with any image that already exists in the destination. In addition, you can stretch or shrink the copied picture.
|
![]() |
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. Read EarthWeb's privacy statement. |