Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Array of Webbrowser controls in vb.net

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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
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

610 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