|
|
 |
 |
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
(Publisher: The Coriolis Group)
Author(s): Steven Holzner
ISBN: 1576102831
Publication Date: 08/01/98
Chapter 14 The Frame, Label, Shape, And Line Controls
- If you need an immediate solution to:
- Adding A Frame To A Program
- Setting Frame Size And Location
- Dragging And Dropping Controls
- Grouping Controls In A Frame
- Adding A Label To A Program
- Using Labels Instead Of Text Boxes
- Formatting Text In Labels
- Aligning Text In Labels
- Handling Label Control Events
- Using Labels To Give Access Keys To Controls Without Captions
- Adding A Shape Control To A Program
- Drawing Rectangles
- Drawing Squares
- Drawing Ovals
- Drawing Circles
- Drawing Rounded Rectangles
- Drawing Rounded Squares
- Setting Shape Borders: Drawing Width, Dashes, And Dots
- Filling Shapes
- Drawing A Shape Without The IDE Grid
- Moving Shapes At Runtime
- Adding A Line Control To A Program
- Drawing Thicker, Dotted, And Dashed Lines
- Drawing A Line Without The IDE Grid
- Changing A Line Control At Runtime
- Using Form Methods To Draw Lines
- Using Form Methods To Draw Circles
In Depth
In this chapter, were going to examine the controls you use to organize and label other controls in a form: the frame, label, shape, and line controls. You use the frame control to create a framea labeled boxin which you can place the following types of controls:
- Label controls to display noneditable text usually used to describe other controls or control groups
- Shape controls to draw circles and boxes in a form
- Line controls to draw lines
These controls are used primarily at design time, but they have their runtime uses as well, as well see. All these controls are intrinsic controlsthat is, they appear in the toolbox when Visual Basic startsand well take a closer look at all these controls now.
The Frame Control
You usually use the frame control to group controls together into a recognizable group. This control appears as a box with a label at upper left. You can make the controls in a frame into a functional group as well, such as when you group option buttons together. When you add option buttons to a frame, those buttons function in concert; when you click one, all the others are deselected. And those option buttons are separate from any other group of option buttons in the form.
The Frame Control tool appears as the third tool down on the left in the Visual Basic toolbox in Figure 14.1.
Figure 14.1 The Frame Control tool.
The Label Control
You use label controls to display text that you dont want the user to change directly. As their name implies, you can use these controls to display text that labels other parts of the form that dont have their own captions. For example, you might label a picture box something like Current image, or a text box New setting.
Despite their name, label controls are not static. You can change the text in a label at runtime by setting its Caption property, and in fact thats often a very useful thing to do if you dont want the user to change that text. For example, well see how to build a stopwatch example in this chapter that displays the time in a label control. The label control in that example may be far from what you think of as a standard label, because the text in the label will change, and that text will be large48 point. Its wise to remember that labels can indeed display any kind of textyou can even format, word wrap, or size a label to fit its text. All in all, labels are one of the most useful Visual Basic controls. They can even have Click events and access keys, as well see in this chapter.
The Label Control tool appears in the toolbox in Figure 14.2 as the second tool down on the left. Just about every Visual Basic programmer is familiar with this control, but well see some new label tricks in this chapter.
Figure 14.2 The Label Control tool.
The Shape Control
The shape control is a graphical control. You can use this control to draw predefined colored and filled shapes, including rectangles, squares, ovals, circles, rounded rectangles, or rounded squares.
You use the shape control at design time to draw shapes in a form. Theres no great programming complexity hereyou just use this control as a design element to add rectangles, circles, and so on to your forms. In this way, the shape control is a little like the frame control; however, shapes cant act as control containers (for example, you cant group option buttons together with shapes or move the controls inside them en masse). Still, shapes certainly come in more varieties than frames do.
Although shape controls are one of the Visual Basic intrinsic controls, Visual Basic programmers remain largely ignorant of them. Thats too bad, because you can create some nice effects with shapes, as well see here.
The Shape Control tool appears in the Visual Basic toolbox in Figure 14.3 as the ninth tool down on the left.
Figure 14.3 The Shape Control and Line Control tools.
The Line Control
Like the shape control, the line control is a graphical control. You use it to display horizontal, vertical, or diagonal lines in a form. You can use these controls at design time as a design element or at runtime to alter the original line you drew.
Drawing lines is easyyou just click the Line Control tool in the toolbox, press the mouse button when the cursor is at the lines start location on the form, and drag the mouse to the end position of the line. When you release the mouse, the line appears with sizing handles at each end that you can use to change the line as you like. You can also change a line at runtime by changing its X1, X2, Y1, and Y2 properties.
You can draw lines with this control in forms, picture boxes, and frames. In fact, lines drawn with the line control stay visible even if its containers AutoRedraw property is set to False. (The line control even has its own Visible property, which means you can make lines appear and disappear.) The Line Control tool appears in the toolbox in Figure 14.3 as the ninth tool down on the right.
|