如何打开在外部浏览器web浏览器控制的链接? [英] How to open a link in webBrowser control in external browser?

查看:275
本文介绍了如何打开在外部浏览器web浏览器控制的链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本框和WebBrowser控件在我的Windows窗体应用程序。当用户输入一个HTML code在文本框中WebBrowser控件显示其编译形式。在$ C $下这样的:

I have a textBox and a webBrowser control in my Windows Forms application. Whenever a user enters a HTML code in textBox, the webBrowser control shows its compiled form. The code for this:

private void textBox2_TextChanged(object sender, EventArgs e)
{
    webBrowser1.DocumentText = textBox2.Text;
}

但每当我点击WebBrowser控件的链接,它会打开它在同一WebBrowser控件。我要的是,它应该在系统默认的Web浏览器中打开。那么,有没有处理的链接点击无论如何这web浏览器的控制?

But whenever I click a link in the webBrowser control, it opens it in the same webBrowser control. What I want is that it should open in default web browser of the system. So is there any event for this webBrowser control that handles link clicking?

推荐答案

要做到这一点,最简单的方法是拦截<一href="http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.navigating.aspx">Navigating事件。

The easiest way to do this would be to intercept the Navigating event.

public void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
    //cancel the current event
    e.Cancel = true;

    //this opens the URL in the user's default browser
    Process.Start(e.Url.ToString());
}

这篇关于如何打开在外部浏览器web浏览器控制的链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆