开发者

How do I create a link using C#?

Could anyone tell me how to create a link from a LinkLabel in Visual Studio?

Say I'm trying to make the program pull up a browser window to www.google.com (in their default browser). How would I do that? I got the following from some example code I found:

        HttpWebRequest head_request = (HttpWebRequest)WebRequest.Create("http开发者_如何学编程://www.google.com");
        head_request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0a2) Gecko/20110613 Firefox/6.0a2";
        HttpWebResponse response = (HttpWebResponse)head_request.GetResponse();

But what I have doesn't do anything. If anything, it makes my browser go into a state of unresponsiveness.

I have

using System.Net;
using System.IO;

up top. Is that right? Thanks in advance!


What you can do like something below:

ProcessStartInfo sInfo = new ProcessStartInfo("http://mysite.com/");  
Process.Start(sInfo);

An article about it: http://support.microsoft.com/kb/320478

Attach it to a link:

protected void hyperlink_Click(object sender, EventArgs e)
{
   ProcessStartInfo sInfo = new ProcessStartInfo("http://mysite.com/");  
   Process.Start(sInfo);
}

Note: If you can't see it, then you should declare using System.Diagnostics; namespace.


The code below will open google.com in the default browser. You can call this code from anywhere. The click event of a button would be a good place to test it out!

Process.Start("http://google.com/");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜