Tuesday, July 21, 2015

Labels in Visual Basic.NET



Labels
Label is an object used to display text strings, but cannot receive input by the user. If you want to edit label’s content, you can use vb codes or change the text’s properties on Properties panel.
Here’s a demonstration on how to use label in visual basic.net program.
1.   Open the toolbox panel, then click Common Controls > Label. Drag it to the form.
2.   Enter three labels, Label1, Label2 and Label3.
3.   Select Label1, open Properties panel, and find Text properties:
4.   Change the text properties to “Name”.
5.   With the same method, change Label2’s text property to “Address”.
6.   For Label3, you can leave it untouched. We’ll change it using vbnet codes. Double click on the form. Code window will emerge, and automatically created a procedure for handling event Form1_Load.
7.   The codes will be like this:
 Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub
End Class

8.   Enter codes below between Private Sub clause and End Sub clause.
Me.Label3.Text = "Work and Hobby"

9.   Save the codes you entered by using CTRL + S.

10. If you run the program, the appeareance will be like this, you can see Label3 has different text, although in the Design view, it has other text. It’s because you command the vbcompiler to change the label3’s text during the loading of the Form.
label, visual basic, vb,net

The result of the program

No comments: