// NewWindow3 event, used on Windows XP SP2 and higher
            public void NewWindow3(ref object ppDisp, ref bool Cancel, uint dwFlags, string bstrUrlContext, string bstrUrl)
            {
                BrowserNavigationEventArgs args = new BrowserNavigationEventArgs(ppDisp, new Uri(bstrUrl), null, (EnumUrlContext)dwFlags);

                _webBrowser.OnStartNewWindow(args);
                Cancel = args.Cancel;
                ppDisp = args.AutomationObject;
            }
            //The NewWindow2 event, used on Windows XP SP1 and below
            public void NewWindow2(ref object pDisp, ref bool cancel)
            {
                BrowserNavigationEventArgs args = new BrowserNavigationEventArgs(pDisp, null, null, EnumUrlContext.None);

                _webBrowser.OnStartNewWindow(args);
                cancel = args.Cancel;
                pDisp  = args.AutomationObject;
            }
        protected void OnStartNewWindow(BrowserNavigationEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }
            bool allowPopup = (e.NavigationContext == EnumUrlContext.None) || ((e.NavigationContext & EnumUrlContext.OverrideKey) == EnumUrlContext.OverrideKey);

            if (!allowPopup)
            {
                switch (_popupLevel)
                {
                case EnumPopupLevel.AllowAllPopups:
                    allowPopup = true;
                    break;

                case EnumPopupLevel.AllowSecureSites:
                    if (EncryptionLevel != WebBrowserEncryptionLevel.Insecure)
                    {
                        allowPopup = true;
                        break;
                    }
                    else
                    {
                        goto EnumPopupLevel_BlockMost;
                    }

                case EnumPopupLevel.BlockMost:
EnumPopupLevel_BlockMost:
                    if ((e.NavigationContext & EnumUrlContext.UserFirstInited) == EnumUrlContext.UserFirstInited
                        &&
                        (e.NavigationContext & EnumUrlContext.UserInited) == EnumUrlContext.UserInited)
                    {
                        allowPopup = true;
                    }
                    break;
                }
            }
            if (allowPopup)
            {
                if (this.StartNewWindow != null)
                {
                    this.StartNewWindow(this, e);
                }
                if (e.Cancel)
                {
                    if (_webBrowser2 != null)
                    {
                        e.AutomationObject = _webBrowser2.Application;
                    }
                }
            }
            else
            {
                e.Cancel = true;
            }
        }
 protected void OnStartNavigate(BrowserNavigationEventArgs e)
 {
     if (e == null)
     {
         throw new ArgumentNullException("e");
     }
     if (this.StartNavigate != null)
     {
         this.StartNavigate(this, e);
     }
 }
            //Implement whichever events you wish
            public void BeforeNavigate2(object pDisp, ref object URL, ref object flags, ref object targetFrameName, ref object postData, ref object headers, ref bool cancel)
            {
                Uri urlUri = new Uri(URL.ToString());

                string tFrame = null;

                if (targetFrameName != null)
                {
                    tFrame = targetFrameName.ToString();
                }
                if (_webBrowser != null)
                {
                    BrowserNavigationEventArgs args = new BrowserNavigationEventArgs(pDisp, urlUri, tFrame, EnumUrlContext.None);
                    _webBrowser.OnStartNavigate(args);

                    cancel = args.Cancel;
                }
            }