Mouse Event for detecting if mouse is hovering over URL-VBForums
Results 1 to 3 of 3

Thread: Mouse Event for detecting if mouse is hovering over URL

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2012
    Posts
    70

    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
    Posts
    8,242

    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
    2.  
    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
    13.  
    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
    Location
    WindowFromPoint
    Posts
    4,246

    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

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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.