Label Control
Description
Label controls are used to display text or images that cannot be edited by the user. They are used to identify objects on a form to provide a description of what a certain control will do if clicked, for example, or to display information in response to a run-time event or process in your application. Because the Label control cannot receive focus, it can also be used to create access keys for other controls.
Usage
Use the Label control to display static text on your form.
Typically, label controls are used to provide a text label for another control. For example, if you have a ListBox control on a form, you can put a Label control above the listbox with the name of the list. In the example below, a label with the Text property set to "Part Numbers:" is used to label a list box.
Setting Label Appearance
Use the BorderStyle, ForeColor, BackColor, Font, Image, ImageAlign, and TextAlign properties to change the appearance of the label.
Using hotkeys (mnemonics)
You can designate a character in the label's Text property to be a hotkey.
In the Text property of the label, use the ampersand character (&) before the hotkey.
For example, in the example shown above, the Text property for the label is "Part &Numbers:".
At runtime, when the user types Alt+N, the focus will go to the listbox.
When using hotkeys, be sure that the tab order is set so that the label's TabIndex is one before the control's TabIndex that is labeled. See the section Changing Tab Order.
Label Control Properties
Property | Description |
---|---|
BackColor | The background color for the control. Default: Control |
BorderStyle | The border used for the control. Default: None |
Enabled | Sets whether the control is enabled at runtime. Default: True |
EventTaskType | The type of task used for events. Default: Normal |
Font | The font for the control text. Default: Microsoft Sans Serif 8.25 pt |
FontBold | The bold attribute for the current font Default: False |
FontItalic | The italic attribute for the current font Default: False |
FontName | The name for the current font Default: Microsoft Sans Serif |
FontSize | The size for the current font in points Default: 8.25 |
ForeColor | The foreground color for the control text. Default: ControlText |
Height | The height of the control in pixels. |
Image | The picture for the control. To delete, press the [Delete] key. Default: Empty |
ImageAlign | The picture alignment for the control. Default: MiddleCenter |
Left | The left coordinate of the control in pixels. |
Name | The name of the control. Default: LabelXX |
TabIndex | The tab index of the control. |
Text | The text of the control. Default: Name of control |
TextAlign | Selects the text alignment. Default: TopLeft |
ToolTipText | The text used in the control’s tooltip. Default: Empty |
Top | The top coordinate of the control in pixels. |
Visible | Whether the control is visible or not at runtime. Default: True |
Width | The width of the control in pixels. |
Label Control Events
Event | Description |
---|---|
Click | Executes when the user clicks the control with the mouse. |
DblClick | Executes when the user double clicks the control with the mouse. |