0% found this document useful (0 votes)
61 views18 pages

Visual Programming: Linklabel Lab 8

A LinkLabel control allows displaying hyperlinks and inherits properties from the Label control. It can be created at design time by dragging it from the toolbox onto a form or at runtime by instantiating the LinkLabel class. Key properties like text, color, font and hyperlink attributes can be set either in the properties window or programmatically. To complete addition of the control, it must be added to the form's Controls collection.

Uploaded by

Kamran khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views18 pages

Visual Programming: Linklabel Lab 8

A LinkLabel control allows displaying hyperlinks and inherits properties from the Label control. It can be created at design time by dragging it from the toolbox onto a form or at runtime by instantiating the LinkLabel class. Key properties like text, color, font and hyperlink attributes can be set either in the properties window or programmatically. To complete addition of the control, it must be added to the form's Controls collection.

Uploaded by

Kamran khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Visual Programming

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

• After you place a LinkLabel control on a Form,


the next step is to set properties.
• The easiest way to set properties is from the
Properties Window.
• You can open Properties window by pressing
F4 or right click on a control and select
Properties menu item. The Properties window
looks like Figure 2.

6
Design Time:Setting LinkLabel Properties

7
Setting LinkLabel Properties
• Name

• Name property represents a unique name of a


LinkLabel control. It is used to access the control in
the code. The following code snippet sets and gets
the name and text of a LinkLabel control.

• dynamicLinkLabel.Name = "DynamicLinkLabel";
• string name = dynamicLinkLabel.Name;
8
Setting LinkLabel Properties
• Location, Height, Width, and Size

• The Location property takes a Point that specifies the starting


position of the LinkLabel on a Form. The Size property specifies the
size of the control. We can also use Width and Height property
instead of Size property. The following code snippet sets Location,
Width, and Height properties of a LinkLabel control.

• dynamicLinkLabel.Location = new Point(20, 150);


• dynamicLinkLabel.Height = 40;
• dynamicLinkLabel.Width = 300;

9
Setting LinkLabel Properties
• Background, Foreground, BorderStyle

• BackColor and ForeColor properties are used to set background and


foreground color of a LinkLabel respectively. If you click on these
properties in Properties window, the Color Dialog pops up.

• Alternatively, you can set background and foreground colors at run-


time. The following code snippet sets BackColor and ForeColor
properties.

• 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.

• dynamicLinkLabel.Font = new Font("Georgia", 16);

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.

• dynamicLinkLabel.Font = new Font("Georgia", 16);

12
Setting LinkLabel Properties
• Text and TextAlign, and TextLength

• Text property of a LinkLabel represents the current text of a LinkLabel


control. The TextAlign property represents text alignment that can be Left,
Center, or Right. The TextLength property returns the length of a LinkLabel
contents.

• The following code snippet sets the Text and TextAlign properties and gets
the size of a LinkLabel control.

• dynamicLinkLabel.Text = "I am Dynamic LinkLabel";


• dynamicLinkLabel.TextAlign = HorizontalAlignment.Center;
• int size = dynamicLinkLabel.TextLength;

13
Setting LinkLabel Properties
• Hyperlink Properties

• Here are the hyperlink related properties available in the LinkLabel control.

• Links and LinkArea

• 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.

• dynamicLinkLabel.LinkArea = new LinkArea(0, 22);


• dynamicLinkLabel.Links.Add(24, 9, "http://www.c-sharpcorner.com");
• dynamicLinkLabel.LinkClicked += new LinkLabelLinkClickedEventHandler(LinkedLabelClicked);
• Here is the code for the LinkLabel click event handler and uses Process.Start method to open a hyperlink in a browser.

14
Setting LinkLabel Properties
• LinkColor, VisitedLinkColor, ActiveLinkColor and DisabledLinkColor

• LinkColor, VisitedLinkColor, ActiveLinkColor and DisabledLinkColor


properties represent colors when a hyperlink is in normal, visited,
active, or disabled mode. The following code snippet sets these
colors.

• 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.

• In the first step, we create an instance of the


LinkLabel class. The following code snippet creates a
LinkLabel control object.

• LinkLabel dynamicLinkLabel = new LinkLabel();

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.

• // Set background and foreground


• dynamicLinkLabel.BackColor = Color.Red;
• dynamicLinkLabel.ForeColor = Color.Blue;

• dynamicLinkLabel.Text = "I am a Dynamic LinkLabel";
• dynamicLinkLabel.Name = "DynamicLinkLabel";
• dynamicLinkLabel.Font = new Font("Georgia", 16);

• In the last step, we need to add a LinkLabel control to the Form by calling
Form.Controls.Add method. The following code snippet adds a LinkLabel control to a Form.

• Controls.Add(dynamicLinkLabel);

17
Questions?

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy