Solved

Array of Webbrowser controls in vb.net

Posted on 2004-08-16
3
349 Views
Last Modified: 2008-03-17
Want to create a control array of webbrowser controls...want to add and remove controls from this array at runtime.

This code, which uses the CollectionBase, doesn't work...says that the Webbrowser has no default property and can't be indexed.

What does work?

----------------------------------

Public Class cWBCollection
 
    Inherits System.Collections.CollectionBase
    Private ReadOnly HostForm As System.Windows.Forms.Form

    Public Function AddNew() As AxSHDocVw.AxWebBrowser
        Dim WB As New AxSHDocVw.AxWebBrowser()

        Me.List.Add(WB)
        HostForm.Controls.Add(WB)
        Return WB
    End Function

    Public Sub New(ByVal host As System.Windows.Forms.Form)
        HostForm = host
        Me.AddNew()
    End Sub

    Default Public ReadOnly Property Item(ByVal Index As Integer) As AxSHDocVw.AxWebBrowser
        Get
            Return CType(Me.List.Item(Index), SHDocVw.WebBrowser)
        End Get
    End Property

    Public Sub Remove()
        If Me.Count > 0 Then
            HostForm.Controls.Remove(Me(Me.Count - 1))
            Me.List.RemoveAt(Me.Count - 1)
        End If
    End Sub
End Class
0
Comment
Question by:rdavis101
  • 2
3 Comments
 
LVL 10

Expert Comment

by:prakash_prk
ID: 11818020
pass the form object as reference

 Public Sub New(Byref host As System.Windows.Forms.Form)
        HostForm = host
        Me.AddNew()
End Sub

regards
Prakash
0
 
LVL 10

Accepted Solution

by:
prakash_prk earned 125 total points
ID: 11818059
Your code works well on my machine . I can add and remove items easily .

When you get the error??

regards
Prakash
0
 

Author Comment

by:rdavis101
ID: 11818325
I've been coding for about 20 hours straight now. Guess I've been staring at code too long. Problem was that when the collection was created, the Me.AddNew function was called resulting in a nonnavigated browser on the form. I was subsequently calling Addnew like this:

    Dim cWB As New cWBCollection(Me)  '<---Immediately after Windows Form Designer generated code

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim WB As New AxSHDocVw.AxWebBrowser()
        WB = cWB.AddNew()
        WB.GoHome()
        Button1.Text = cWB.Count
    End Sub

Clicking Button 1 resulted in a navigated browser, but I couldn't see it, because it was under the nonnavigated version. How about that. Solution was to delete Me.AddNew from the New function of the Collection case...no more non-navigated browser on startup.

Roger
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
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…

707 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

14 Experts available now in Live!

Get 1:1 Help Now