accessing properties after dynamically creating a webbrowser control

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Ive been trying to workout how to write two subrutines for a simple webbrowser app.
I havent had any luck to date and dont even know if i am on the right track.
The app consist of
1. a form1,
2. toolstrip control with a textbox and four buttons on the toolstrip control,
3. tabcontrol with no tabs at design time
*At runtime for each new tab a dynamically created webbrowser control is added to the tab.
If you read the comments in the application code for the two subrutines you will understand what i need to do.
Thanks in advance for any helpImports System.Windows.Forms


Public Class Form1

Private Sub Form1_Load(ByVal sender As system.Object, ByVal e As system.EventArgs) Handles MyBase.Load


End Sub

Private Sub ToolStripButton1_Click(ByVal sender As system.Object, ByVal e As system.EventArgs) Handles ToolStripButton1.Click
*******************************
Nead code here to tell the webbrowser control on the active tab
to navigate to address provide in ToolStripText1 control.
*******************************

THIS ISNT CLOSE
Dim aBrowser As WebBrowser
Dim webaddress As String = ToolStripTextBox1.Text
aBrowser.Navigate(webaddress)
Dim x As Integer = TabControl1.TabIndex - 1
TabControl1.TabPages.Item(x).Text = WebBrowser1.DocumentTitle
End Sub

Private Sub ToolStripTextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ToolStripTextBox1.KeyPress
If e.KeyChar = Chr(13) Then
ToolStripButton1_Click(sender, e)
Else

End If
End Sub

Private Sub ToolStripButton4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton4.Click
Dim webaddress As String = ToolStripTextBox1.Text
Dim aBrowser As New WebBrowser
aBrowser.Dock = DockStyle.Fill

Dim x As Integer = TabControl1.TabCount
TabControl1.TabPages.Add("New")
TabControl1.TabPages.Item(x).Controls.Add(aBrowser)
TabControl1.SelectedTab = TabControl1.TabPages.Item(x)
aBrowser.Navigate(webaddress)

Add a click Event for the button
AddHandler aBrowser.DocumentCompleted, AddressOf MyDocCompletedSub
End Sub

Private Sub MyDocCompletedSub(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)
********************************
need to change the active tabs text property to the
browser documentTitle here.
********************************

THIS ISNT CLOSE
Dim aBrowser As New WebBrowser
Dim x As Integer = TabControl1.TabCount - 1
TabControl1.TabPages.Item(x).Text = aBrowser.DocumentTitle
TabControl1.TabPages.Item(x).Text = TabControl1.TabPages.Item(x).Controls.Item(0).Name
End Sub

Private Sub ToolStripButton5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton5.Click
Dim x As Integer = TabControl1.TabIndex
End Sub

Private Sub HomeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HomeToolStripMenuItem.Click
Dialog1.ShowDialog()
End Sub

End Class


Im new to .Net, OOP and this forum but love it!

View the full article
 
Back
Top