Question Handling events from WebBrowser objects contained in an ArrayList?

simonrichards150

New member
Joined
Jul 18, 2009
Messages
2
Programming Experience
3-5
Hello, i'm new ;)

I was hoping someone could help me out here. I'm writing a tabbed web browser for someone who is learning VB.NET, and I have got to the point where I can add/remove browser controls into tab pages, controlled by one set of buttons on the main form, but I can't handle events from the WebBrowser objects.

I have tried this but it says that 'DocumentTitleChanged' isnt an event of 'Control'...

VB.NET:
Dim browser As New ArrayList


browser.Add(New WebBrowser)
browser(0).parent = TabControl1.SelectedTab
browser(0).dock = DockStyle.Fill
[B]AddHandler browser(0).DocumentTitleChanged, TitleChangedHandler()[/B]

I want to update the tab title with the web page title when it changes. I started using a timer to update the tabs but there must be a way to add an event handler here!

What do you reckon i'm doing wrong?
 
First up, consider your nomenclature. Is "browser" really an appropriate name of an ArrayList of WebBrowser objects? The name of that variable should be something like "browsers" or "browserList", which actually indicate what it is. It's not a browser so it shouldn't be named "browser".

As for the question, you shouldn't be using ArrayLists in .NET 2.0 or later. With the introduction of generics you should be using a generic List, in your case a List(Of WebBrowser). Unlike an ArrayList it will only accept WebBrowser objects and it will return its items as WebBrowser references.

Finally, you shouldn't be using 0 as the index because 0 will get the first item every time. If you've just added a new item then it will be at the end of the collection, not the beginning. As such you need the last index, not the first.
 
Thanks for taking the time to reply, I got it sorted myself though. I am now using a list(of webbrowser) and don't worry, i'm not using index 0 all the time, that code is just for populating the first tab :)
 
Back
Top