.net Windows应用程序中如何通过单击链接按钮打开浏览器?

.net Windows应用程序中如何通过单击链接按钮打开浏览器?

问题描述:

亲爱的,

我的问题是,我使用了一个链接按钮.当我单击该按钮时,它应该打开浏览器.我需要此问题的代码.请同时发送c#.net Windows和Web应用程序.


谢谢与问候,

Viswanathan.M

Dear,

My question is, I have use one link button.When i click that button,it should open a browser.I need code for this issue. Kindly send for both c#.net windows and web applications.


Thanks& Regards,

Viswanathan.M

string targetURL = @"http://pedroliska.com";
System.Diagnostics.Process.Start(targetURL);
string targetURL = @"http://pedroliska.com";
System.Diagnostics.Process.Start(targetURL);


使用Process.Start,并指向要打开的URL,它将使用默认浏览器将其打开.那是一个Windows应用程序.在Web应用程序中,您只需要放置一个超链接,然后放置target ="_ blank",这样该链接就会在新窗口中打开.
Use Process.Start, and point to the URL you want to open, it will open it with the default browser. That''s a windows app. In a web app, you just put a hyperlink, and put target="_blank", so the link opens in a new window.


某些应用程序的所有运行均不好-使用会更好地知道该如何开始以及如何进行.当您需要启动某些URL时,它还不错-2irfanshaikh已经提供了正确的答案.

但是真正的选择是在应用程序内部运行浏览器.只需使用类System.Windows.Forms.WebBrowser,请参见 http://msdn.microsoft.com /en-us/library/system.windows.forms.webbrowser.aspx [ http://msdn.microsoft.com/en-us/library/system.windows.controls.webbrowser.aspx [
All those runs of some applications are not good — the use knows better what to start and how. As you need to start certain URL, it''s not that bad — you already have a correct answer by 2irfanshaikh.

But the real alternative would be running a browser inside your application. Just use the class System.Windows.Forms.WebBrowser, see http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.aspx[^].

That was for System.Windows.Forms. There is such thing for WPF as well: System.Windows.Controls.WebBrowser, see http://msdn.microsoft.com/en-us/library/system.windows.controls.webbrowser.aspx[^].

—SA