The linklabel control is similar to the linklabel control, but it can be applied to Windows Forms.ProgramAdd a link to the web style,
You can set part of the text (text value) in the linklabel as a link to the webpage.
Common attributes of the linklabel Control
Activelinkcolor: Specifies the color of the link to be clicked.
Linkcolor: the initial color of the link.
Visitedlinkcolor: The color after the link is clicked.
Disabledlinkcolor: The color when the link is disabled.
Linkarea: displays the text area of a hyperlink.
Linkbehaviour: indicates the link behavior.
DOCK: Layout of links in containers
Example of using linkarea: If you need to display the "link" in "test link effect" as a hyperlink
ExampleCodeAs follows:
Linklabel1.linkarea = new linkarea (2, 2 );
Commonly used linklabel controls
Focus method: This method indicates that the control sets the input focus.
Findform method: This method is used to retrieve the form of the control.
Linkclicked event: When you click a link in the control, process the linkclicked event to execute the task, and pass the instance of the link labellinkclickedeventargs class to the handler of the linkclicked event, this instance contains the linklabel associated with the clicked link. link object. You can use the information specified in the linkdata attribute of the linklabel. Link class to determine the link you have clicked or the task type you want to execute after clicking the link.
If you need to click a link to open a webpage, the sample code is as follows:
View plaincopy to clipboardprint?
01. Private void lbllink_linkclicked (Object sender, linklabellinkclickedeventargs E)
02 .{
03. system. Diagnostics. process. Start ("iexplore.exe", "http://www.google.cn /");
04 .}
Private void lbllink_linkclicked (Object sender, linklabellinkclickedeventargs E)
{
System. Diagnostics. process. Start ("iexplore.exe", "http://www.google.cn /");
}
You can also write the code as follows:
View plaincopy to clipboardprint?
01. Private void lbllink_linkclicked (Object sender, system. Windows. Forms. linklabellinkclickedeventargs E)
02 .{
03. This. lbllink_linkclicked.links [0]. linkdata = "http://www.sina.com /";
04. system. Diagnostics. process. Start (E. Link. linkdata. tostring ());
05 .}
Private void lbllink_linkclicked (Object sender, system. Windows. Forms. linklabellinkclickedeventargs E)
{
This. lbllink_linkclicked.links [0]. linkdata = "http://www.sina.com /";
System. Diagnostics. process. Start (E. Link. linkdata. tostring ());
}
You can add multiple links to the linklable control, for example:
View plaincopy to clipboardprint?
01. Private void form1_load (Object sender, eventargs E)
02 .{
03. lbllink. Text = "csdn win Baidu Google Yahoo ";
04. lbllink. Links. Add (0, 4, "http://www.csdn.net /");
05. lbllink. Links. Add (9, 2, "http://www.baidu.com /");
06. lbllink. Links. Add (12, 2, "http://www.google.cn /");
07. lbllink. Links. Add (15, 5, "http://www.yahoo.com.cn /");
08 .}
Private void form1_load (Object sender, eventargs E)
{
Lbllink. Text = "csdn win Baidu Google Yahoo ";
Lbllink. Links. Add (0, 4, "http://www.csdn.net /");
Lbllink. Links. Add (9, 2, "http://www.baidu.com /");
Lbllink. Links. Add (12, 2, "http://www.google.cn /");
Lbllink. Links. Add (15, 5, "http://www.yahoo.com.cn /");
}
The code for clicking a link to open the webpage is as follows:
View plaincopy to clipboardprint?
01. Private void lbllink_linkclicked (Object sender, linklabellinkclickedeventargs E)
02 .{
03. lbllink. Links [lbllink. Links. indexof (E. Link)]. Visited = true;
04. String TargetUrl = E. Link. linkdata as string;
05. If (string. isnullorempty (TargetUrl ))
06. MessageBox. Show ("no link address! ");
07. Else
08. system. Diagnostics. process. Start ("TargetUrl ");
09 .}
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/yinyaling/archive/2010/02/25/5326582.aspx