Web Development

Make the most of your graphics with VB6's PictureClip control

If you have a lot of graphical resources—particularly small ones such as icons and toolbar buttons—you should look into using VB's PictureClip Control. See how this handy control can help you organize and utilize your graphical resources.

Visual Basic's PictureClip control can simplify the organization and use of graphical resources in your program. It is most commonly used with small graphics that you have a lot of, such as icons and toolbar buttons.

With the PictureClip control, you can create a single graphical image that contains all the individual icons or buttons, and then extract each one for display as needed. The PictureClip control itself is never visible onscreen when the program is running.

To use this control, you must select Microsoft PictureClip Control 6.0 in the Components dialog box. Then, place it on the form where it will be needed. You can load the composite image at design time or at run time:

PictureClip1.Picture = LoadPicture("c:\images\icons.bmp")

Once the image is loaded, you can retrieve any arbitrary portion of it by setting the ClipX and ClipY properties to specify the top left corner of the region and the ClipHeight and ClipWidth properties to specify the size. Then, the Clip property retrieves the region for use in, for example, a PictureBox control:

PicClip1.ClipX = 20
PicClip1.ClipY = 34
PicClip1.ClipWidth = 22
PicClip1.ClipHeight = 22
Picture1.Picture = PicClip1.Clip

You can also divide the composite image into a rectangular grid of same-size sections, and then retrieve a section based on its position. This technique is used when the composite image contains a collection of same-size sub-images such as you might use for a toolbar. You can set the number of rows and columns at design time or at run time via the Cols and Rows property. Then retrieve an individual subimage using the GraphicCell property:

Picture1.Picture = PicClip1.GraphicCell(2)

The top left cell is index 0 and this value increases from left to right and then top to bottom.

Advance your scripting skills to the next level with TechRepublic's free Visual Basic newsletter, delivered each Friday. Automatically sign up today!

0 comments

Editor's Picks