C# webBrowser 开新窗口保持Session

 

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);
         }

 

posted @ 2011-05-25 22:36  C#&SQL  阅读(778)  评论(0)    收藏  举报