Results 1 to 3 of 3
  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2012

    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).

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012

    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:
    1. Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
    3.         Try
    4.             Dim el = WebBrowser1.Document.GetElementFromPoint(PointToClient(Cursor.Position))
    5.             If el.TagName = "A" Then
    6.                 Me.Text = el.GetAttribute("href")
    7.             Else
    8.                 Me.Text = ""
    9.             End If
    10.         Catch
    11.             Me.Text = ""
    12.         End Try
    14.     End Sub
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006

    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.

    Private Sub WebBrowser1_StatusTextChanged(sender As Object, e As System.EventArgs) Handles WebBrowser1.StatusTextChanged
        Label1.Text = WebBrowser1.StatusText
    End Sub

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Click Here to Expand Forum to Full Width

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.