Advice needed on VB.NET code.

Posted on 2012-09-06
Last Modified: 2012-09-07

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
Question by:NaanPLS
    LVL 74

    Expert Comment

    by:käµfm³d 👽
    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?

    Author Comment

    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.
    LVL 74

    Expert Comment

    by:käµfm³d 👽
    Remove the "Handles_ webBrowser1.DocumentCompleted" code, and in your For loop add the following:

    AddHandler NB.DocumentCompleted, AddressOf webBrowser1.DocumentCompleted

    Open in new window


    Author Comment

    Then i get Error      
    'webBrowser1' is not declared. It may be inaccessible due to its protection level.
    LVL 74

    Accepted Solution

    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


    Author Closing Comment


    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now