|
Label, LinkLabel
Label
Labels are those controls that are used to display text in other parts of the
application. They are based on the Control class.
Notable property of the label control is the text property
which is used to set the text for the label.
Label Event
The default event of Label is the Click event
which looks like this in code:
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)_
Handles Label1.Click
End Sub
|
Creating a Label in Code
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)_
Handles MyBase.Load Dim Label1 As New Label()
Label1.Text = "Label"
Label1.Location = New Point(135, 70)
Label1.Size = New Size(30, 30)
Me.Controls.Add(Label1)
End Sub
|
LinkLabel
LinkLabel is similar to a Label but they display a hyperlink. Even multiple hyperlinks
can be specified in the text of the control and each hyperlink can perform a different
task within the application. They are based on the Label class
which is based on the Control class.
Notable properties of the LinkLabel control are the ActiveLinkColor, LinkColor and LinkVisited which
are used to set the link color.
LinkLabel Event
The default event of LinkLabel is the LinkClicked event
which looks like this in code:
Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs)_
Handles LinkLabel1.LinkClicked
End Sub
|
Working with LinkLabel
Drag a LinkLabel (LinkLabel1) onto the form. When we click this LinkLabel it will take
us to "www.startvbdotnet.com". The code for that looks like
this:
Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal_
e As System.Windows.Forms.LinkLabelLinkClickedEventArgs)_
Handles LinkLabel1.LinkClicked
System.Diagnostics.Process.Start("www.startvbdotnet.com")
'using the start method of system.diagnostics.process class
'process class gives access to local and remote processes
End Sub
|
Creating a LinkLabel in Code
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)_
Handles MyBase.Load
Dim LinkLabel1 As New LinkLabel()
LinkLabel1.Text = "Label"
LinkLabel1.Location = New Point(135, 70)
LinkLabel1.Size = New Size(30, 30)
Me.Controls.Add(LinkLabel1)
End Sub
|
|