Solved

Array of Webbrowser controls in vb.net

Posted on 2004-08-16
3
367 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

691 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