Home » VB.NET Label Control

VB.NET Label Control

by Online Tutorials Library

VB.NET Label Control

In VB.NET, a label control is used to display descriptive text for the form in control. It does not participate in user input or keyboard or mouse events. Also, we cannot rename labels at runtime. The labels are defined in the class System.Windows.Forms namespace.

Let’s create a label in the VB.NET Windows by using the following steps:

Step 1: We have to drag the Label control from the Toolbox and drop it on the Windows form, as shown below.

VB.NET Classes and Object

Step 2: Once the Label is added to the form, we can set various properties to the Label by clicking on the Label control.

VB.NET Label Properties

Properties Description
AutoSize As the name defines, an AutoSize property of label control is used to set or get a value if it is automatically resized to display all its contents.
Border Style It is used to set the style of the border in the Windows form.
PreferredWidth It is used to set or get the preferred width for the Label control.
Font It is used to get or set the font of the text displayed on a Windows form.
PreferredHeight It is used to set the height for the Label Control.
TextAlign It is used to set the alignment of text such as centre, bottom, top, left, or right.
ForeColor It is used to set the color of the text.
Text It is used to set the name of a label in the Windows Form.
ContextMenu It is used to get or sets the shortcut menu associated with the Label control.
DefaultSize It is used to get the default size of the Label control.
Image It is used to set the image to a label in Windows Form.
ImageIndex It is used to set the index value to a label control displayed on the Windows form.

VB.NET Label Events

Events Description
AutoSizeChanged An AutoSizeChanged event occurs in the Label control when the value of AutoSize property is changed.
Click Click event is occurring in the Label Control to perform a click.
DoubleClick When a user performs a double-clicked in the Label control, the DoubleClick event occurs.
GotFocus It occurs when the Label Control receives focus on the Window Form.
Leave The Leave event is found when the input focus leaves the Label Control.
TabIndexChanged It occurs when the value of Tabindex property is changed in the Label control.
ControlRemoved When the control is removed from the Control.ControlCollection, a ControlRemoved event, occurs.
TabStopChanged It occurs when the property of TabStop is changed in the Label Control.
BackColorChanged A BackColorChanged event occurs in the Label control when the value of the BackColor property is changed.
ControlAdded When a new control is added to the Control.ControlCollection, a ControlAdded event occurs.
DragDrop A DragDrop event occurs in the Label control when a drag and drop operation is completed.

Furthermore, we can also refer to the VB.NET Microsoft documentation to get a complete list of Label properties and events.

Let’s create a program to display the Label controls in VB.NET.

Label.vb

Output:

VB.NET Classes and Object

We have created 5 Labels on the Windows Form by using drag and drop operation in the above output.

Example2: Write a program to display only Labels on Windows forms.

Form1.vb

Output:

VB.NET Classes and Object

We can also load an image in the Label Control by using the following statement in the program.


You may also like