?
Solved

Advice needed on VB.NET code.

Posted on 2012-09-06
6
Medium Priority
?
531 Views
Last Modified: 2012-09-07
Hi,

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
            TabControl1.SelectedTab.Controls.Add(NB)
            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("someurl.net")
        Next
        TabControl1.SelectedIndex = 0
        Form2.Show()
        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
Naan_PLS
0
Comment
Question by:NaanPLS
  • 3
  • 3
6 Comments
 
LVL 75

Expert Comment

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

Author Comment

by:NaanPLS
ID: 38374832
If i try:

    Private Sub WebBrowser1_DocumentCompleted(sender As System.Object, e As_
 System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles_
 ebBrowser1.DocumentCompleted
                 
                   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.
0
 
LVL 75

Expert Comment

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

AddHandler NB.DocumentCompleted, AddressOf webBrowser1.DocumentCompleted

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:NaanPLS
ID: 38374850
Then i get Error      
'webBrowser1' is not declared. It may be inaccessible due to its protection level.
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 38374904
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

0
 

Author Closing Comment

by:NaanPLS
ID: 38375532
Thanks..
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

850 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