Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Array of Webbrowser controls in vb.net

Posted on 2004-08-16
3
Medium Priority
?
390 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 500 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

810 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