vbnet
  1. vbnet-label-control

Working with Forms and Controls in VB.NET Label Control

Labels in VB.NET are used to display text that cannot be edited by the user. In this page, we will discuss how to work with label controls in VB.NET.

Syntax

Here is the syntax for creating a label control programmatically and adding it to a form:

Dim label1 As New Label
label1.Text = "This is a label control"
label1.Location = New System.Drawing.Point(50, 50)
Me.Controls.Add(label1)

Here is the syntax for creating a label control in the form designer:

  1. Open the form in design mode.
  2. Drag the Label control from the Toolbox to the form.
  3. Set the properties of the label such as Text, Font, and Location using the Properties window.

Example

Here's an example of how to create and use a label control in VB.NET:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim label1 As New Label
    label1.Text = "This is a label control"
    label1.Location = New System.Drawing.Point(50, 50)
    Me.Controls.Add(label1)
End Sub

Output

When you run the code, you will see a form with a label control that displays the text "This is a label control" at the location set in the code.

Explanation

A label control is used to display text that cannot be edited by the user. The label control can be created programmatically or in the form designer. The label control has properties that can be set to customize the appearance, such as Text, Font, and Location.

Use

Label controls are useful for displaying static information, such as informative text, titles, or captions. You can use label controls to provide instructions to users, describe the purpose of controls, or provide context for other items on the form.

Important Points

  • Label controls are used to display static text that cannot be edited by users.
  • The Label control can be created programmatically or in the form designer.
  • Label control properties can be set to customize the appearance.

Summary

In this page, we discussed how to work with label controls in VB.NET. We covered the syntax, example, output, explanation, use, important points, and summary of label controls. By using label controls, you can provide context and informative text to users in your VB.NET applications.

Published on: