Mouse Event for detecting if mouse is hovering over URL
Okay, so I have a basic web browser project (back/forward buttons, stop/refresh, and all the necessary components). I am using the Webbrowser object provided in the toolbox. How can I have it so that when the mouse hovers over a link inside the browser, it displays the link as a string on a label on the form (I.e a status label to tell what URL the mouse is hovering over).
Re: Mouse Event for detecting if mouse is hovering over URL
Unfortunately webbrowser has no mouse events of its own so you'll have to do this on a timer, something like this ...
vb.net Code:
Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
Try
Dim el = WebBrowser1.Document.GetElementFromPoint(PointToClient(Cursor.Position))
If el.TagName = "A" Then
Me.Text = el.GetAttribute("href")
Else
Me.Text = ""
End If
Catch
Me.Text = ""
End Try
End Sub
Re: Mouse Event for detecting if mouse is hovering over URL
WebBrowser.StatusText Property
The status text contains the URL of a hyperlink when the mouse pointer hovers over it, handle the StatusTextChanged event.
Code:
Private Sub WebBrowser1_StatusTextChanged(sender As Object, e As System.EventArgs) Handles WebBrowser1.StatusTextChanged
Label1.Text = WebBrowser1.StatusText
End Sub