解决WebBrowser中打开链接调用IE窗口问题
一、使用NewWindow3 事件。
引入SHDocVw.dll//本想将这个dll文件一起打包提供下载,但没找到粘贴附件的地方。需要的朋友自己去找了。
using SHDocVw;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
namespace WindowsApplication24
...{
public partial class Form1 : Form
...{
public Form1()
...{
InitializeComponent();
this.webBrowser1.Navigate("about:blank");
(this.webBrowser1.ActiveXInstance as SHDocVw.WebBrowser).NewWindow3 += new SHDocVw.DWebBrowserEvents2_NewWindow3EventHandler(Form1_NewWindow3);
}
void Form1_NewWindow3(ref object ppDisp, ref bool Cancel, uint dwFlags, string bstrUrlContext, string bstrUrl)
...{
Cancel = true;
this.webBrowser1.Navigate(bstrUrl);
}
private void button1_Click(object sender, EventArgs e)
...{
this.webBrowser1.Navigate("http://www.google.cn/");
}
}
}
二。给出一个链接:http://hi.baidu.com/zhitenglin/blog/item/5d1614f3b09fe6cc0a46e011.html