Microsoft Office Tutorials and References
In Depth Information
The Image Control
The Image control is a relatively simple control that allows you to display a picture on a form.
It supports only these file formats: BMP, CUR, GIF, ICO, JPG, and WMF.
The Picture property contains the actual binary picture image that will be displayed in the
control. In the Visual Basic Editor, you can enter the name of a file and it will automatically
load the image for you. However, if you want to load an image while the program is running,
you will need to use the LoadPicture function like this, where <pathname> contains the file
name and path.
Image1.Picture = LoadPicture(< pathname >)
By default, when a picture is loaded into the control, either initially in the Visual Basic Editor
or in your application, the picture will be displayed at its normal size. This means that you
will see the complete picture only if the image control is the same size as the image. If the con
trol is smaller than the image, you will see only the upper-left corner of the image, but if the
control is larger than the image, you’ll see the entire image, plus the background of the control.
The PictureAlignment property controls how the image is placed in the control. By default,
the picture is aligned such that the upper-left corner of the picture is placed in the upper-left
corner of the control ( fmPictureAlignmentTopLeft ). However, you can set this property to
these values as well: fmPictureAlignmentTopRight , fmPictureAlignmentCenter ,
fmPictureAlignmentBottomLeft , and fmPictureAlignmentBottomRight .
You can use the PictureSizeMode property to automatically resize the image to see the entire
picture. A value of fmPictureSizeModeStretch resizes the image to fill the entire space of the
control. However, you might need to adjust the Height and Width properties to prevent the
image from being distorted. Setting this property to fmPictureSizeModeZoom will enlarge or
shrink the picture to fit the box, but it won’t change its height-to-width ratio. A value of
fmPictureSizeModeClip displays the image at normal size and chops off any part of the image
that will not fit into the control.
When the PictureTiling property is Tr ue , the image is repeated as many times as necessary to
fill up the area available in the image control. The first copy of the image is placed according
to the PictureAlignment property.