Devi creare una classe personalizzata del controllo WebBrowser e instanziarla nella Form di utilizzo:
Nella form in cui hai inserito un TabControl vuoto:codice:Public Class WebBrowserArray Inherits System.Collections.CollectionBase Private ReadOnly HostForm As System.Windows.Forms.Form Public Event DocumentCompleted(ByVal url As String, ByVal container As Integer) Public Event ProgressChanged(ByVal Maximun As Integer, ByVal Current As Integer) Public Event Navigating(ByVal url As String) Public Event Navigated(ByVal url As String) Public Sub New(ByVal host As System.Windows.Forms.Form) HostForm = host End Sub Public Function AddNewWebBrowser(ByVal index As Integer, ByVal controllo As Windows.Forms.Control) As System.Windows.Forms.WebBrowser Dim aWebBrowser As New System.Windows.Forms.WebBrowser() Me.List.Add(aWebBrowser) HostForm.Controls.Add(aWebBrowser) aWebBrowser.Tag = index aWebBrowser.Name = "WebBrowser" & index aWebBrowser.Parent = controllo aWebBrowser.Dock = DockStyle.Fill AddHandler aWebBrowser.ProgressChanged, AddressOf ProgressChangedHandler AddHandler aWebBrowser.Navigating, AddressOf NavigatingHandler AddHandler aWebBrowser.Navigated, AddressOf NavigatedHandler AddHandler aWebBrowser.DocumentCompleted, AddressOf DocumentCompletedHandler Return aWebBrowser End Function Private Sub ProgressChangedHandler(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserProgressChangedEventArgs) Try RaiseEvent ProgressChanged(e.MaximumProgress, e.CurrentProgress) Catch ex As Exception End Try End Sub Private Sub NavigatingHandler(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatingEventArgs) Try RaiseEvent Navigating(e.Url.AbsoluteUri) Catch ex As Exception End Try End Sub Private Sub NavigatedHandler(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatedEventArgs) Try RaiseEvent Navigated(e.Url.AbsoluteUri) Catch ex As Exception End Try End Sub Private Sub DocumentCompletedHandler(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Try RaiseEvent DocumentCompleted(e.Url.AbsoluteUri, sender.tag.ToString) Catch ex As Exception End Try End Sub Default Public ReadOnly Property Item(ByVal Index As Integer) As _ System.Windows.Forms.WebBrowser Get Return CType(Me.List.Item(Index), System.Windows.Forms.WebBrowser) End Get End Property Public Overloads ReadOnly Property Count(ByVal Index As Integer) As Integer Get Return Me.Count End Get End Property Public Sub Remove() ' Check to be sure there is a button to remove. If Me.Count > 0 Then ' Remove the last button added to the array from the host form ' controls collection. Note the use of the default property in ' accessing the array. HostForm.Controls.Remove(Me(Me.Count - 1)) Me.List.RemoveAt(Me.Count - 1) End If End Sub End Class
a te il resto.....codice:MyWebBrowserArray = New WebBrowserArray(Me) MyWebBrowserArray.AddNewWebBrowser(TabControl1.SelectedIndex, TabControl1.TabPages.Item(TabControl1.SelectedIndex)) MyWebBrowserArray.Item(TabControl1.SelectedIndex).Navigate("http://forum.html.it")

Rispondi quotando