How to use LinkLabel?
-
Dear friends, I intend to use LinkLabels in my project. But I am toally jumbled with it because I am not getting the exact place where the actual link should be stored. I studied its properties like LinkArea, LinkData, Links and Link types. But I am totally entangled with it. I want to display a text and underlying link and connect it to webbrowser. the later part is easy coz' I know LinkLabel's event to handle. But Plz help me with above problem. Thanks in Advance..
-
Dear friends, I intend to use LinkLabels in my project. But I am toally jumbled with it because I am not getting the exact place where the actual link should be stored. I studied its properties like LinkArea, LinkData, Links and Link types. But I am totally entangled with it. I want to display a text and underlying link and connect it to webbrowser. the later part is easy coz' I know LinkLabel's event to handle. But Plz help me with above problem. Thanks in Advance..
Hello, The following might help you in achieving the desired: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { this.linkLabel1.Text = "Register Online. Visit Microsoft. Visit MSN."; if (this.linkLabel1.Text.Length >= 45) { this.linkLabel1.Links[0].LinkData = "Register"; this.linkLabel1.Links.Add(24, 9, "www.microsoft.com"); this.linkLabel1.Links.Add(42, 3, "www.msn.com"); } } private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { string target = e.Link.LinkData as string; if (null != target && target.StartsWith("www")) { System.Diagnostics.Process.Start(target); } else { MessageBox.Show("Item clicked: " + target); } } } } Regards, Dave
Dave Traister Software Engineer ComponentOne LLC www.ComponentOne.com
-
Dear friends, I intend to use LinkLabels in my project. But I am toally jumbled with it because I am not getting the exact place where the actual link should be stored. I studied its properties like LinkArea, LinkData, Links and Link types. But I am totally entangled with it. I want to display a text and underlying link and connect it to webbrowser. the later part is easy coz' I know LinkLabel's event to handle. But Plz help me with above problem. Thanks in Advance..
Chaitanya Joshi wrote:
I am not getting the exact place where the actual link should be stored
I am not getting what you are saying ? Are you facing difficulty in opening a web page when link button is clicked ? Use
Process.Start
to start a new browser and also send URL to be opened.All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions
-
Hello, The following might help you in achieving the desired: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { this.linkLabel1.Text = "Register Online. Visit Microsoft. Visit MSN."; if (this.linkLabel1.Text.Length >= 45) { this.linkLabel1.Links[0].LinkData = "Register"; this.linkLabel1.Links.Add(24, 9, "www.microsoft.com"); this.linkLabel1.Links.Add(42, 3, "www.msn.com"); } } private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { string target = e.Link.LinkData as string; if (null != target && target.StartsWith("www")) { System.Diagnostics.Process.Start(target); } else { MessageBox.Show("Item clicked: " + target); } } } } Regards, Dave
Dave Traister Software Engineer ComponentOne LLC www.ComponentOne.com
Thank You Sir. The code snippet you gave worked perfectly fine. So finally the "linkdata" is the attribute where we've to add the actual link.