webbrowser 2.0 NewWindow

ImDaFrEaK

Well-known member
Joined
Jan 7, 2006
Messages
416
Location
California
Programming Experience
5-10
Can anyone tell me how to send newly opened windows back to my own WebBrowser control?

I am working on an application that works a lot like the current tab browsing browsers. Whenever I click on a link inside of the WebBrowser control from my application it opens the window in a new Internet Explorer window. I want to re-direct the new link to my own WebBrowser control or a new WebBrowser control.
 
You would normally handle NewWindow event, but the 2.0 control only allows Cancel here, you also need the Url the new window is supposed to navigate to. There is a fix/hack here:
http://forums.microsoft.com/msdn/showpost.aspx?postid=7228&siteid=1
http://lab.msdn.microsoft.com/ProductFeedback/viewFeedback.aspx?feedbackid=c5aa05c2-73ce-40af-b6b1-7b5900cf4e9f

Here is an example I tested and worked just fine, add the vb.net module from first link (first post, first codebox), add an empty tabcontrol to a new form, call method addfirsttab on form load. All 'open link in new window' will now generate a new tabpage and navigate there instead.
VB.NET:
Sub addfirsttab()
  addtab("http://www.vbdotnetforums.com")
End Sub
 
Sub addtab(ByVal url)
  Dim tp As New TabPage
  Dim wb As New ExtendedWebBrowser
  AddHandler wb.NewWindowExtended, AddressOf wb_NewWindowExtended
  AddHandler wb.Navigated, AddressOf wb_Navigated
  wb.Dock = DockStyle.Fill
  tp.Controls.Add(wb)
  TabControl1.TabPages.Add(tp)
  wb.Navigate(url)
End Sub
 
Private Sub wb_NewWindowExtended(ByVal sender As Object, ByVal e As Module1.WebBrowserNewWindowExtendedEventArgs)
  e.Cancel = True
  addtab(e.Url)
End Sub
 
Private Sub wb_Navigated(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatedEventArgs)
  sender.parent.text = sender.Document.Title
End Sub
 
Unfortunately, I get this:
Private Sub wb_NewWindowExtended(ByVal sender As Object, ByVal e As Module1.WebBrowserNewWindowExtendedEventArgs)
e.Cancel = True
addtab(e.Url)
End Sub
Module1.WebBrowserNewWindowExtendedEventArgs is not defined.

Please can you help me fix this. Thanks.
 
Reply

Yes, thats where I got the code from, infact, I got it from your post. But how do I fix that error? Please, this has been bugging me since 9:00 AM this morning. (In the UK it's now 17:04)
 
You have to follow the instructions to add those classes.
 
You have to follow the instructions to add those classes.

Just soon as you replied that I realised what I had to do :) Just now, one slight problem. The program won't even start! Now I get this:
An error occurred creating the form. See Exception.InnerException for details. The error is: Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "MyWeb.Form1.resources" was correctly embedded or linked into assembly "MyWeb Internet Browser" at compile time, or that all the satellite assemblies required are loadable and fully signed.

Thanks for all your help so far, you've been ace! Just need to get this fixed then I have a finished web browser..
 
Back
Top