Comparing the Picture Box and Image ControlsThe picture box control and the image control both do basically the same thing. They allow you to place pictures, from graphics files, on a form. The two controls differ in these respects:
Both the image control and picture box control support the following graphics file formats:
Several files with these formats appear in the Graphics folder that you installed (or have the option of installing) with Visual Basic. The most important property of both the image control and the picture box control is the Picture property, which holds the graphic. At design time, you can double-click the Properties window's Picture property to display a File Open dialog box and select a graphics file that has one of the required filename extensions. When you want to display an image at runtime, you must use the LoadPicture() internal function to associate a graphic file's location to the Picture property of the control. The following assignment associates a graphic to a picture box's Picture property: picPortrait.Picture = LoadPicture("c:\MyPhotos\Charlie.wmf") Notice that you don't directly assign the path and file to the Picture property. The LoadPicture() function is the most important function to master when using the image and picture box controls. Here's the full format of the LoadPicture() internal function: LoadPicture([GraphicFileName] [,varSize] [,varColorDepth], [varX, varY]) Notice that the graphics filename, the first argument of LoadPicture(), is optional. If you call the LoadPicture() function without specifying the filename, Visual Basic will erase the picture from the control. Table 14.1 lists the named constants you can use for the varSize argument if you specify this argument. The varSize argument specifies the image's size for icons and cursors. The varSize argument is critical because users often use their Control Panel's display settings to determine the size of cursors and icons on their system. You can access these system values. Table 14.1. Specify one of these varSize constants to control the LoadPicture() image size if you load an icon or cursor file.
Table 14.2 lists the values you can use for the optional varColorDepth argument when you place icons and cursors. Table 14.2. Specify one of these varColorDepth constants to control the LoadPicture() color depth if you load an icon or cursor file.
The varX and varY values are required if you use either the vbLPSmallShell or vbLPLargeShell size values. When you place image and picture box controls on a form, they respond slightly differently, even if you place them at the same size measurements and point their respective Picture properties to the same graphics file. You must set an image control's Stretch property to True before you set the image control's Width and Height properties. If you do not, the width and height will shrink or expand to the size of the bitmap you place in the control and change the Width and Height settings automatically. When you place a picture box control on a form, the image automatically expands or shrinks to fill your size measurements for the control. Therefore, the picture box control will always change the size of its image to conform to your size property values, but the image control changes your size property values until you set its Stretch property to True.
You can place a graphics file as your form's background. |