Advice needed on VB.NET code.


I must start with telling you, I'm new to .NET programming, so you might think this is a dumb question.

I'm trying to make a multi tabbed form with 10 WebBrowser controls.
I have added and named the TabPages and WebBrowser controls programmatically.
Unfortunately I cant compile the code if I use the names.

I believe there must be a way to tell the compiler, that it has to accept/skip them?
I have tried to set the Form's title to the current url, when the url is changed, in the selected tab,, as well as Setting the selected TabPage's text tag, with the title of the current document, without any succes. I can't find the right event to handle or code it without using the page and control names.  

Any help would be greatly appreciated !!

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Me.WindowState = FormWindowState.Maximized
        For i = 0 To 9
            TabControl1.TabPages.Add("Tab " + (i + 1).ToString)
            Dim NB As New WebBrowser
            NB.Dock = DockStyle.Fill
            TabControl1.SelectedIndex = i
            CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Name = "WebBrowser" + (i + 1).ToString
            TabControl1.SelectedTab.Name = "Tab" + (i + 1).ToString
            CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigate("")
        TabControl1.SelectedIndex = 0
        IsLoaded = True
    End Sub
    Public Sub UpdateTitles(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.Click
        If IsLoaded = False Then Return
        Dim WBT = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser)
        Dim MyTxT = WBT.DocumentTitle.ToString
        Dim MyTxT1 = WBT.Url.ToString
        TabControl1.SelectedTab.Text = MyTxT
        Me.Text = MyTxT1
    End Sub

Open in new window

Best Regards
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
I must start with telling you, I'm new to .NET programming, so you might think this is a dumb question.
In my opinion, there are dumb questions, but they are typically only dumb to the person who knows the answer. If you don't know the answer to a question, and you never ask the question, then that is truly dumb, as you are now living in ignorance  = )

Don't worry about asking any question you have--especially when you are just starting out. I would be hard-pressed to find anyone participating on this site who is going to think you are dumb for asking a question. After all, it is a question-and-answer site!

As to your question...

What error message do you receive from the compiler?
NaanPLSAuthor Commented:
If i try:

    Private Sub WebBrowser1_DocumentCompleted(sender As System.Object, e As_
 System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles_
                   Some code here...

    End Sub

Open in new window

I get this compiler error:
Handles clause requires a WithEvents variable defined in the containing type or one of its base types.
käµfm³d 👽Commented:
Remove the "Handles_ webBrowser1.DocumentCompleted" code, and in your For loop add the following:

AddHandler NB.DocumentCompleted, AddressOf webBrowser1.DocumentCompleted

Open in new window

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

NaanPLSAuthor Commented:
Then i get Error      
'webBrowser1' is not declared. It may be inaccessible due to its protection level.
käµfm³d 👽Commented:
My fault. It was supposed to be an underscore, not a dot (effectively, the name of the method you want to be the handler):

AddHandler NB.DocumentCompleted, AddressOf WebBrowser1_DocumentCompleted

Open in new window


Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NaanPLSAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.