2008-10-06 30 views

cevap

19

Sadece cevabı arayan bir saat harcadım, bu yüzden sonuçları burada yayınlayayım. NewWindow olayını yakalamak için SHDocVwCtl.WebBrowser_V1 nesnesini kullanabilirsiniz.

NOT: Kod http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_21484555.html#discussion

//-------------------------------VB.NET Version:------------------------------- 

Dim WithEvents Web_V1 As SHDocVwCtl.WebBrowser_V1 

Private Sub Form_Load() 
    Set Web_V1 = WebBrowser1.Object 
End Sub 

Private Sub Web_V1_NewWindow(ByVal URL As String, ByVal Flags As Long, ByVal TargetFrameName As String, PostData As Variant, ByVal Headers As String, Processed As Boolean) 
    Processed = True 
    WebBrowser1.Navigate URL 
End Sub 


//-------------------------------C# Version------------------------------- 

private SHDocVw.WebBrowser_V1 Web_V1; //Interface to expose ActiveX methods 

private void Form1_Load(object sender, EventArgs e) 
{ 
    //Setup Web_V1 interface and register event handler 
    Web_V1 = (SHDocVw.WebBrowser_V1)this.webBrowser1.ActiveXInstance; 
    Web_V1.NewWindow += new SHDocVw.DWebBrowserEvents_NewWindowEventHandler(Web_V1_NewWindow); 
} 

private void Web_V1_NewWindow(string URL, int Flags, string TargetFrameName, ref object PostData,string Headers, ref bool Processed) 
{ 
    Processed = true; //Stop event from being processed 

    //Code to open in same window 
    this.webBrowser1.Navigate(URL); 

    //Code to open in new window instead of same window 
    //Form1 Popup = new Form1(); 
    //Popup.webBrowser1.Navigate(URL); 
    //Popup.Show(); 
} 
+0

SHDocVw hangi bileşende tanımlıdır? En azından mshtml.dll dosyasında bulamıyorum. –

+4

Ben% wındır bulunur düşünüyorum% \ system32 \ shdocvw.dll –

+0

Obejet kendisini herkesin gettinf Bu bana çok iyi –

3

den biraz Greg'in cevabın versiyonunu temizledik. Geçilen denetimin davranışını, genel bir değişkene dayanmak yerine değiştirir. Kullanımı:

InlinePopups(webBrowser1); 

Kodu:

// interface to expose ActiveX methods 
private SHDocVw.WebBrowser_V1 Web_V1; 
private void InlinePopups(WebBrowser browser) 
{ 
    // hooks to force new windows to open in the current instance 
    Web_V1 = (SHDocVw.WebBrowser_V1)browser.ActiveXInstance; 
    Web_V1.NewWindow += new SHDocVw.DWebBrowserEvents_NewWindowEventHandler((string URL, int Flags, string TargetFrameName, ref object PostData, string Headers, ref bool Processed) => 
    { 
     Processed = true; // stop event from being processed 

     // open in the existing window 
     browser.Navigate(URL); 
    }); 
} 

Hala elbette% WINDIR% \ system32 \ shdocvw.dll, başvurusunu ihtiyacı vardır.

İlgili konular