Contents
Label Sample Help

Sample Description: Label

Points of Interest

Text Alignment in Labels

Label BorderStyles

WordWrap in Labels

Creating Labels with Multiple Lines

Creating a Group of Option Buttons

Control

Label

For Help on Help, Press F1


Label

A label displays information to a user that cannot be changed while the application is running. The information commonly provided by a label includes headings or other descriptive text on the form. Most often, this control is used to display a meaningful name that describes the purpose of a TextBox, ListBox, or ComboBox control.

The Caption property defines the text string that is displayed in the label. You can define a one-line text string to the Caption property while in Edit mode, or you can assign a string to the Caption property in code while in run mode. This string contains carriage returns that allow a multiple-line label to be created while in run mode, if necessary. Set the WordWrap property to True to display variable length lines or a varying number of lines.

In the sample application, click the various option buttons to change the Alignment and BorderStyle properties. The results will be immediately displayed in the Welcome label shown at the bottom of the sample form. Clicking the CheckBox will toggle the value of the WordWrap property. When set to True, the text string will automatically wrap to the next line if the length of the text information exceeds the width of the label.


Text Alignment in Labels

The Height, Width, Left and Top properties determine the size and location of the label on the form. The Alignment property is used to specify how the label's caption aligns with the label. The value of Alignment is as follows:

Alignment Value	Alignment

0	Left (default)

1	Right

2	Center


Label BorderStyles

To further define the way a label looks, you can set the BorderStyle. The BorderStyle property setting defines whether or not the label has a border. When the BorderStyle value is set to 0, the default, the label will not have a border. When the BorderStyle is set to 1 (Fixed Single), a thin black rectangle will appear around the label.

When a BorderStyle of 1 is used, you can provide even more contrast to the label by changing the BackColor property to something other than the form's current color. You can also set the ForeColor property to change the color of the label's text string.


WordWrap in Labels

The WordWrap property determines if the caption text is permitted to wrap to multiple lines if the length of the caption's text is larger than the width of the label. If the WordWrap property is set to False, the caption text is displayed on a single line. If the length of the text is larger than the width of the label, some of the text will not be displayed.

When the WordWrap property is set to True, whole words will wrap to the next line in the label. If a word is longer than the width of the label, it will not wrap and some of it will not be displayed. Words cannot be split between multiple lines with the WordWrap property.


Creating Labels with Multiple Lines

The WordWrap property can wrap whole words to create a multiple line caption text. In some cases, you may wish to have a multiple-line caption that breaks word or characters in specific places.

The Chr function is frequently used to add linefeeds and carriage returns to labels and message strings. This way, a label or message box can display multiple lines of information. The ANSI value of 13 and 10 are special characters that correspond to the carriage return and line feed, respectively. You can define multi-line labels through program code by using the following the example:

Sub Button1_Click()

  Dim multiline_string As String

  multiline_string  = "This is an example" & Chr(13) & Chr(10) & "of a multi-line string."

  Label1.Caption = multiline_string

End Sub

You can define a multi-line label in the Property Editor by following the steps below:

1.	Click on the Caption property.

2.	In the "Value" box of the Property Editor, type the following:

This is an example^Mof a multi-line string.
("This is an example" is the first line text string.  ^M is a manually inserted Carriage Return/Linefeed. The last line text string is "of a multi-line string."

3.	Click the OK button on the Property Editor to accept the caption. Your label should look like this if the Width and Height properties are large enough.

This is an example

of a mult-line string.


Creating a Group of Option Buttons

When OptionButton's are created in "groups" only one of the OptionButtons can have a Value of "1" or True. In this sample application, there are two groups of OptionButtons:  Alignment and Border Style.

When OptionButton's are created in sequence (i.e., one after another), they are automatically grouped together. In this sample application, the three OptionButtons under the Alignment Label were created one after another. Then, the Border Style Label was added. Adding a different type of control broke the automatic grouping of OptionButtons. Next, the two OptionButtons for the Border Style options were added. Since they were added one after another, they were automatically grouped together.