Visual Programming: Linklabel Lab 8
Visual Programming: Linklabel Lab 8
LinkLabel
LAB 8
Muhammad kamran
Email: kamran_comsian@ymail.com
LinkLabel control
• A LinkLabel control is a label control that can
display a hyperlink.
• A LinkLabel control is inherited from the Label
class so it has all the functionality provided by
the Windows Forms Label control.
• LinkLabel control does not participate in user
input or capture mouse or keyboard events.
2
Creating a Link Label
• There are two ways to create a control.
– Design Time
– Run Time
3
Design Time
• First, we can use the Form designer of Visual Studio to
create a control at design-time.
• In design-time mode, we can use visual user interfaces to
create a control properties and write methods.
• To create a LinkLabel control at design-time, you simply
drag and drop a LinkLabel control from Toolbox to a Form.
• After you drag and drop a LinkLabel on a Form. The
LinkLabel looks like Figure 1.
• Once a LinkLabel is on the Form, you can move it around
and resize it using mouse and set its properties and events.
4
Design Time
System.Diagnostics.Process.Start("http://emr.byethost31.com"); 5
Figure 1
Design Time: Setting LinkLabel Properties
6
Design Time:Setting LinkLabel Properties
7
Setting LinkLabel Properties
• Name
• dynamicLinkLabel.Name = "DynamicLinkLabel";
• string name = dynamicLinkLabel.Name;
8
Setting LinkLabel Properties
• Location, Height, Width, and Size
9
Setting LinkLabel Properties
• Background, Foreground, BorderStyle
• dynamicLinkLabel.BackColor = Color.Red;
• dynamicLinkLabel.ForeColor = Color.Blue;
10
Setting LinkLabel Properties
• Font
• Font property represents the font of text of a
LinkLabel control. If you click on the Font property
in Properties window, you will see Font name, size
and other font options. The following code
snippet sets Font property at run-time.
11
Setting LinkLabel Properties
• Font
• Font property represents the font of text of a
LinkLabel control. If you click on the Font property
in Properties window, you will see Font name, size
and other font options. The following code
snippet sets Font property at run-time.
12
Setting LinkLabel Properties
• Text and TextAlign, and TextLength
• The following code snippet sets the Text and TextAlign properties and gets
the size of a LinkLabel control.
13
Setting LinkLabel Properties
• Hyperlink Properties
• Here are the hyperlink related properties available in the LinkLabel control.
• A LinkLabel control can display more than one hyperlink. The Links property a type of LinkCollection represents all the
hyperlinks available in a LinkLabel control. The Add method of LinkColleciton is used to add a link to the collection. The
Remove and RemoveAt methods are used to remove a link from the LinkCollection. The Clear method is used to remove
all links from a LinkCollection.
• LinkArea property represents the range of text that is treated as a part of the link. It takes a starting position and length
of the text.
• The following code snippet ads a link and sets LinkArea and a link click event handler.
14
Setting LinkLabel Properties
• LinkColor, VisitedLinkColor, ActiveLinkColor and DisabledLinkColor
• dynamicLinkLabel.ActiveLinkColor = Color.Orange;
• dynamicLinkLabel.VisitedLinkColor = Color.Green;
• dynamicLinkLabel.LinkColor = Color.RoyalBlue;
• dynamicLinkLabel.DisabledLinkColor = Color.Gray;
15
Run-time
• LinkLabel class represents a hyperlink Label control.
We simply create an instance of LinkLabel class, set
its properties and add this it to the Form controls.
16
Run-time
• In the next step, we set properties of a LinkLabel control. The following code snippet sets
background color, foreground color, Text, Name, and Font properties of a LinkLabel.
17
Questions?