Visual Basic .NET - Label Control

The VB.NET Label control is used to display text on a form. Here are some of its common properties:

Properties:

  • Text: Gets or sets the text displayed by the control.
  • Font: Gets or sets the font used to display the control's text.
  • ForeColor: Gets or sets the color of the control's text.
  • BackColor: Gets or sets the background color of the control.
  • TextAlign: Gets or sets the alignment of the text within the control.
  • AutoSize: Gets or sets a value indicating whether the control resizes to fit its contents.
  • Visible: Gets or sets a value indicating whether the control is visible.

Methods:

  • Focus(): Sets input focus to the control.
  • Refresh(): Invalidates the control and causes it to be redrawn.
  • PerformClick(): Simulates a click on the control.

Events:

  • Click: Occurs when the control is clicked.
  • DoubleClick: Occurs when the control is double-clicked.
  • MouseHover: Occurs when the mouse pointer rests on the control.
  • MouseLeave: Occurs when the mouse pointer leaves the control.
  • Here is an example of setting the Text property of a Label control in VB.NET:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Label1.Text = "Hello, World!"
End Sub

In this example, the Text property of the Label control named "Label1" is set to the string "Hello, World!" when the form is loaded.