instance of a form that contains a web browser ~ how do I access

simpleonline

Active member
Joined
Sep 13, 2011
Messages
33
Programming Experience
Beginner
I have create a form with a web browser on it. I create an instance of that form that contains web browser.
how can I edit the web browser document completed on the new instance?
Thanks
 
Last edited:
You can add event handlers using either a WithEvents variable or AddHandler statement. That's all there is to that. WithEvents variable is suitable if you only have a single object instance at a time.

Now you can either handle the event of the browser control in the other form, or you can declare an event in other form (that you raise when its browser raises event) and handle that.
 
I've tried something like this but not getting a positive result.

VB.NET:
Public Class NewWindow
 
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim mystuff As New PopOutWindow
'PopOutWindow is the form that contains the webbrowser 
 
End Sub
 
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles mystuff.WebBrowser1.DocumentCompleted
 
For Each element As HtmlElement In Mystuff.WebBrowser1.Document.Getelementsbytagname("input")
If element.GetAttribute("title") = "Google Search" Then
element.SetAttribute("value", textbox2.Text)
End If
Next
End Sub
 
 
Private Sub NewWindow_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
 
End Sub
End Class
 
Last edited:
If you want to use WithEvents/Handles you have to declare the WithEvents variable in the class that handles the event.
 

Latest posts

Back
Top