我的 Windows 窗体应用程序中有一个文本框和一个 webBrowser 控件。每当用户在 textBox 中输入 HTML 代码时,webBrowser 控件就会显示其编译后的形式。代码:
private void textBox2_TextChanged(object sender, EventArgs e)
{
webBrowser1.DocumentText = textBox2.Text;
}
但是每当我单击 webBrowser 控件中的链接时,它都会在同一个 webBrowser 控件中打开它。我想要的是它应该在系统的默认网络浏览器中打开。那么这个 webBrowser 控件是否有处理链接点击的事件?
最佳答案
最简单的方法是拦截 Navigating事件。
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());
}
关于c# - 如何在外部浏览器中打开 webBrowser 控件中的链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18035579/