Private Sub ActiveBrowser_Navigating

Untouchable

Member
Joined
Aug 6, 2006
Messages
11
Programming Experience
Beginner
Well, im making a tabbed webbrowser (turns out to be much harder then I thought), and i have the basic features done, but now im trying to set the Browser.navigating and navigated events, and its kinda hard.

Here are some relevant code:

VB.NET:
Dim Browsercollection As New ArrayList

Example:

VB.NET:
Private Sub ToolStripButton5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton5.Click
        Dim ActiveBrowser As WebBrowser = TabControl1.SelectedTab.Tag
        ActiveBrowser = TabControl1.SelectedTab.Tag
        ActiveBrowser.GoHome()

Get how it works? It is the webbrowser that is in the active tab that navigates.. but here comes the hard part..

VB.NET:
Private Sub activebrowser_Navigated(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserNavigatedEventArgs) Handles activebrowser.Navigated
        MessageBox.Show("test")
This doenst work. firstly i get the following error
Handles clause requires a WithEvents variable defined in the containing type or one of its base types
so i tried to add this at the top of the form
Dim WithEvents activebrowser As WebBrowser
and the error message dissappeared, but it doesnt work.. nothing happens when the browser navigates..

Been stuck on this one for days, can anyone clear it for me?

Cheers!
 
Without seeing all the code I would guess that the problem is your scope.

With the first line in the ToolStripButton5_Click method (Dim ActiveBrowser As WebBrowser = ...) you create a variable that has procedural scope. This variable is different than the one "at the top of the form". Variables with procedural scope are only valid while the procedure is running.

Declaring a variable "at the top of the form", i.e. in a class but outside of any methods or propertys (it doesn't have to be at the top) gives it class scope and that variable is valid for the lifetime of the class.

Changing the first line in ToolStripButton5_Click to use the class variable instead of creating another variable should fix the problem.
VB.NET:
ActiveBrowser = TabControl1.SelectedTab.Tag
 
Back
Top