How to handle webbrowser events on tabcontrol

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
2 posts Page 1 of 1
Contributors
User avatar
anthonygz
Member
Member
Posts: 48
Joined: Sun Feb 13, 2011 7:25 pm

Greetings Community!
It's been quite awhile, but I've come back to this forum to get a bit of quick help for a project of mine.
I've been working on a new webbrowser, and have gotten it down to the bone on Anti Pop-Up's, Browsing Speed, and some other things; but that's not what's important here.

I just have a quick question if any of you would be kind enough to answer.

Question:
If i were to be using a "Tabbed" webbrowser, not a normal one;
Would it be possible to handle It's events, if there's not a webbrowser control, but a declared webbrowser control?

This is what i mean:
I have it so that i use CType commands, because I'm using:
Code: Select all
Dim Browser As New WebBrowser
         TabControl1.CreateTab("New Tab")
         TabControl1.SelectedTab.AttachedControl.Controls.Add(Browser)
And the Ctype being:
Code: Select all
CType(TabControl1.SelectedTab.AttachedControl.Controls.Item(0), WebBrowser)

Here's a few key note's here:
I'm Using DotNetBar's Tabbed Control


This COULD be the problem, but it's a bit too late now since it's completely incorporated into my project.

So in the end there's not an actual webbrowser control as stated above, rather I'm creating my own through code.

... and of course, this causes problems; because there's no handler i can use.
Impossible? Possible?

I'm reaching out to YOU, the community, to shed some light on my dilemna.
It may seem silly, but I'm actually quite stuck on figuring out how to do this.
User avatar
comathi
Coding God
Coding God
Posts: 1242
Joined: Fri Mar 26, 2010 1:59 pm

Yes, it's entirely possible to handle WebBrowser events, even if the control is dynamically generated and placed in the TabControl (as is the case for you).

All you have to do is add an event handler to your WebBrowser after you've declared it, for example:
Code: Select all
Dim Browser As New WebBrowser
AddHandler Browser.DocumentCompleted, AddressOf customCompletedHandler
Of course, you can use any WebBrowser event you want, I just used DocumentCompleted as an example :)

You can then add the browser to your tab control as you do already, but you must add a new sub called customCompletedHandler() that will handle the event:
Code: Select all
Private Sub customCompletedHandler()
   'Do stuff
End Sub
I hope that answers your question properly cooll;
2 posts Page 1 of 1
Return to “Coding Help & Support”