Visual Basic Concepts

Using the Line Control

See Also

The line control is used to create simple line segments on a form, a frame, or in a picture box.

Figure 7.30   The line control

You can control the position, length, color, and style of line controls to customize the look of applications. Figure 7.31 shows a line control used to graphically separate the label containing the text "Company Name" from the rest of the form.

Figure 7.31   A line control on a form

The line control has limited functionality and is intended for simple uses — display and printing. Line segments cannot be joined to form other shapes, for instance. For more advanced uses you need to use the line method.

For More Information   See "Using Graphics Methods" in "Working with Text and Graphics" for more information on drawing lines, rectangles, and filled-in boxes at run time using the line method or for more information on drawing circles, ellipses, and arcs at run time using the Circle method.

Setting Border Style and Color

You set the color and style of a line segment by using the BorderStyle and BorderColor properties.

The BorderStyle property provides you with six line styles:

You can specify a line style at design time by choosing the BorderStyle property from the Properties window of the line control or, at run time, by specifying the style using its equivalent Visual Basic constant in code.

The BackColor property is used to specify the color of the line.

At design time, you can set the line color by choosing the BorderColor property from the Properties window of the line control and then selecting from the available palette or system colors.

To set colors at run time, use the Visual Basic color constants (vbGreen, for example) or the system color constants (vbWindowBackground, for example) or the RGB function to specify border colors.

Note   When BorderStyle is set to 0 (Transparent), the BorderColor property is ignored.

For More Information   See "Color Constants" for a list of Visual Basic color constants. See "RGB Function" for information on specifying RGB colors. Also, refer to "Working with Text and Graphics" for detailed information on creating graphics in Visual Basic.

Moving and Sizing a Line Segment

You can move or resize the line control at run time by altering its X1, X2, Y1, and Y2 properties. The X1 and Y1 properties set the horizontal and vertical positions of the left end of the line segment. The X2 and Y2 properties set the horizontal and vertical positions of the right end of the line segment. You can't move a line segment using the Move method.

Drawing Lines on a Form

You can use the line control to draw simple lines on forms.

To draw a line on a form

  1. In the toolbox, select the line control.

    When the pointer moves onto the form, it changes to a cross hair.

  2. Click the form where you want the line to begin and hold down the mouse button.

  3. Drag the cross hair to where you want the line to end and release the mouse button.

  4. From the Properties window, select the BorderStyle property if you want to change the appearance of the line.

  5. In the Settings box, select the style you want.