What is Label Control in VB.net?
A Label Control in VB.net is utilized to display the form’s description.
It doesn’t take part in keyboard, mouse, or user input activities.
Also, runtime label renaming is not possible.
The class System.Windows.Forms namespace contains a definition for the labels.
What is the Purpose of Label Control?
The purpose of the label control is to display the text that the user is not allowed to edit while the application is running.
It does not display the text that is allowed to be edited. The text allowed to be edited is mainly displayed by the text box.
Let’s create a label Control in VB.net by dragging a Label control from the Toolbox and dropping it on the form.
Label Properties in VB.net
The following are some of the commonly used Properties of The Label control in VB.net
|#||Properties and Description|
Gets or sets a value specifying if the control should be automatically resized to display all its contents.
Gets or sets the border style for the control.
Gets or sets the flat style appearance of the Label control
Gets or sets the font of the text displayed by the control.
Gets or sets the height of the font of the control.
Gets or sets the foreground color of the control.
Gets the preferred height of the control.
Gets the preferred width of the control.
Gets or sets a value indicating whether the user can tab to the Label. This property is not used by this class.
Gets or sets the text associated with this control.
Gets or sets the alignment of text in the label.
Methods of the Label Control in VB.net
The following are some of the commonly used Methods of Label Control in VB.net.
|#||Method Name & Description|
Retrieves the size of a rectangular area into which a control can be fitted.
Forces the control to invalidate its client area and immediately redraw itself and any child controls.
Activates the control.
Displays the control to the user.
Returns a String that contains the name of the control.
Events of the Label Control in VB.net
The following are some of the commonly used Events of The Label Control in VB.net.
|#||Event & Description|
Occurs when the value of the AutoSize property changes.
Occurs when the control is clicked.
Occurs when the control is double-clicked.
Occurs when the control receives focus.
Occurs when the input focus leaves the control.
Occurs when the control loses focus.
Occurs when the TabIndex property value changes.
Occurs when the TabStop property changes.
Occurs when the Text property value changes.
What is the Used to Add a Label to a Form?
Label Tool is used to add a Label control to a form.
Label control is used to identify objects on a form, and provide a description of what a certain control will do if clicked.
Example Program in Creating a Label Control in VB.net
Let’s create a program to display the Label controls in VB.net.
Public Class Form1 Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click Label1.Location = New Point(285, 120) Label1.ForeColor = Color.Red Label1.Text = "You have just clicked the label" End Sub End Class
When the above code is executed and run using the Start button available at the Microsoft Visual Studio tool bar, it will show the following window:
Clicking and double-clicking the label would produce the following effect:
What is the Difference Between TextBox and Label Control?
The Difference Between TextBox and Label Control is a Label is meant to be used beside a text box to make a user understand what is to be entered in that text box whereas a text box is used normally for user input.
The contents of a label are not to be directly modified by a user whereas the contents of a text box is for the user to modify.
A Label Control in VB.net is used to display text on a Form.
In this article, we discussed How To Create a Label Control in Windows Forms using VB.net at design time as well as run-time.
After that, we saw how to use various properties and methods.
- Form Controls in VB.net – Windows Form Controls in VB.net
- Basic Controls in VB.net – What are the Basic Controls in VB.net
- Button Control in VB.net – Windows Form Button Control in VB.net