Solved

Array of Webbrowser controls in vb.net

Posted on 2004-08-16
3
350 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

948 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

21 Experts available now in Live!

Get 1:1 Help Now