首先为项目添加引用 Microsoft Internet Controls
class="brush:csharp;gutter:true;">public Form1() { InitializeComponent(); this.webBrowser1.AllowWebBrowserDrop = false; //可在属性里设置,很重要 //在新Form中的WebBrowser中打开 (this.webBrowser1.ActiveXInstance as SHDocVw.WebBrowser).NewWindow2 += new SHDocVw.DWebBrowserEvents2_NewWindow2EventHandler(Form1_NewWindow2); //在主WebBrowser中打开 //(this.webBrowser1.ActiveXInstance as SHDocVw.WebBrowser).NewWindow3 += new SHDocVw.DWebBrowserEvents2_NewWindow3EventHandler(Form1_NewWindow3); } void Form1_NewWindow2(ref object ppDisp, ref bool Cancel) { Form5 frm = new Form5(); //事先建好一个带WebBrowser的窗体 ppDisp = frm.webBrowser1.ActiveXInstance; frm.Show(); } void Form1_NewWindow3(ref object ppDisp, ref bool Cancel, uint dwFlags, string bstrUrlContext, string bstrUrl) { Cancel = true; this.webBrowser1.Navigate(bstrUrl);
//在弹出窗体打开
//Form5 frm = new Form5(); //事先建好一个带WebBrowser的窗体
//frm.webBrowser1.Navigate(bstrUrl);
//frm.Show(); }
转至:http://www.cnblogs.com/swtseaman/archive/2011/10/17/2215714.html