I have a form with a webBrowser object named "myBrowser". When I open a webpage in this browser, I would like to get the id of any element that my mouse is hovering over and show it in a textbox named "txtProperties".
I have tried to achieve this using the following code:
Public Class buildBrowser
Dim myHTMLDocument As HtmlDocument
Private Sub btnBrowseSubmit_Click(sender As Object, e As EventArgs) Handles btnBrowseSubmit.Click
myBrowser.Navigate(txtAddress.Text)
End Sub
Private Sub Document_MouseOver(sender As Object, e As HtmlElementEventArgs)
txtProperties.Text = TryCast(sender, HtmlDocument).GetElementFromPoint(e.ClientMousePosition).GetAttribute("id")
End Sub
Private Sub buildBrowser_Load(sender As Object, e As EventArgs) Handles MyBase.Load
myHTMLDocument = myBrowser.Document
AddHandler myHTMLDocument.MouseOver, AddressOf Document_MouseOver
End Sub
End Class
Running this causes an exception, when the code gets to AddHandler myHTMLDocument.MouseOver, AddressOf Document_MouseOver
saying that a "Null Reference Exception was unhandled" - specifically "An unhandled exception of type 'System.NullReferenceException' occurred in myProgram.exe"
I've not come across this type of error when adding a Handler to an object before before - so any help would be very gratefully received.
Thanks,
Paul.