Microsoft Visual Basic
Standard PictureBox And Image Control
Introduction
The PictureBox control is used to display graphics, to
act as a container for other controls, and to display
output from graphics methods or text using the Print
method.
The Image control is similar to the PictureBox control
in that each can be used to display graphics in the
Visual Basic application. Both supports the same graphic
formats - JPEG, GIF, WMF, EMF, BMP and ICO. However, the
PictureBox control contains functionality which the
Image control does not. For example, the ability to act
as a container for other controls and support for
graphics methods.
The Ilixis Developer's Corner is providing a service to
developers by providing the
source
code of a sample Visual Basic program using
the PictureBox control.
Loading Images
Images can be loaded into the PictureBox control or
Image control at design- time by selecting the Picture
property from the control's Properties window; or at run-time
by using the Picture property and the LoadPicture
function. To clear the graphic from the PictureBox
control or the Image control, use the LoadPicture
function without specifying a file name.
Set Picture1.Picture = LoadPicture ("c:\images\test.bmp",
vbLPLarge, vbLPColor)
Resizing Images and Controls
The Stretch property determines whether the image is
stretched to fit the Image control. If set to TRUE, the
image will stretch to fit the control. Otherwise, the
control will resize to fit the image. Stretching an
image can produce a loss in image quality. However,
Metafiles, which are "draw-type" graphics, are
better suited for stretching.
By default, images are loaded into a PictureBox control
at their original size. If the image is larger than the
control, the image will be clipped — the PictureBox
control does not provide scroll bars. To make a PictureBox
control automatically resize to display an entire image,
set its AutoSize property to True. The control will then
size to the image by growing or shrinking.
Unlike the Image control, the PictureBox control cannot
stretch the image to fit the size of the control.
Graphics Methods (PictureBox Control only)
The PictureBox control can be used to receive the output of graphics methods such as Circle, Line, and Point. For example, you can use the Circle method to draw a circle in a picture box by setting the control's AutoRedraw property to True.
Picture1.AutoRedraw = True
Picture1.Circle (1200, 1000), 750
Setting AutoRedraw to True allows the output from these methods to be drawn to the control and automatically redrawn when the picture box control is resized or redisplayed after being hidden by another object.
Print Method (PictureBox Control only)
The PictureBox control can be used to output text by using the Print method and setting the AutoRedraw property to True.
When using the Print method, the font style and size can
be modified; and the CurrentX, CurrentY, Height, and Width properties
can be used to align text within the PictureBox control.
Picture1.Print "A text string"
Differences between PictureBox and Image controls
The Image control uses fewer system resources and
repaints faster than a PictureBox control, but it
supports only a subset of the PictureBox control's
properties, events, and methods. Both controls support
the same picture formats. However, images can be
stretched in an Image control to fit the control's size.
Stretching cannot be done with the PictureBox control.
|
|
 |
|