C# - Have your desktop application open the system browser in a specific webpage [duplicate]
Possible Duplicate:
Open a URL from Windows Forms
Hello!
I have a C# desktop application and I want to be able to have a link in it that will open a new browser window/tab (on the system default browser) in a specific webpage. I've looked for this in the web but haven't found anything yet. Any help?? thanks...
If you Process.Start the url, that should do the same as ShellExecute, which is the way you'd do it in native code.
You could use a LinkLabel from the toolbox, to get the link onto the form with the proper behaviour. Example code here.
Simpler version:
private void Form1_Shown (object sender, EventArgs e)
{
linkLabel1.Links.Add (0, 7, "http://bobmoore.mvps.org/");
linkLabel1.LinkClicked += new LinkLabelLinkClickedEventHandler(linkLabel1_LinkClicked);
}
private void linkLabel1_LinkClicked (object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
this.linkLabel1.Links[linkLabel1.Links.IndexOf (e.Link)].Visited = true;
string target = e.Link.LinkData as string;
System.Diagnostics.Process.Start (target);
}
You should use a LinkLabel control and Process.Start.
Here is an example how to use it.
PS. You really should start accepting answers if you want to get help in the future.
精彩评论