Advance your scripting skills to the next level with TechRepublic's free Visual Basic newsletter, delivered each Friday. Automatically sign up today!
The Command Button control is widely used in almost every VB6 program. This control usually displays a short text caption that describes its function. However, for some program designs, you may want to get a bit more creative and use graphical buttons that use images instead of text to indicate their function. Many VB programmers don't know that this is a built-in capability of the Command Button control.
When you work with the Command Button, you need to be aware that there are three relevant control properties:
- Picture: The image to display normally.
- DownPicture: The image to display when the button is clicked (in the down state).
- DisabledPicture: The image to display when the button is disabled (when the Enabled property is False).
You can set each of these properties at design time by specifying whether to use a bitmap, icon, or metafile image. You can also set them at runtime by using the LoadPicture function:
Command1.Picture = LoadPicture(filename)
In addition, you must also change the button's style property to 1 - Graphical for the images to display. If the Caption property is not blank, the caption displays along with the graphic. If the graphic is smaller then the button, it will be centered. If it is larger, it will be centered and clipped.