how to read the url under the mouse WebView2

profful

New member
Joined
Nov 14, 2021
Messages
3
Programming Experience
1-3
hi,
how to read the URL under the mouse with a web browser using webview2.
I write the program in VisualBasic2019
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,580
Location
Sydney, Australia
Programming Experience
10+
This works well: Found at: Mouse Event for detecting if mouse is hovering over URL

Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
AddHandler WebBrowser1.Document.MouseOver, AddressOf Me.DisplayHyperlinks
End Sub

Public Sub DisplayHyperlinks(ByVal sender As Object, ByVal e As System.Windows.Forms.HtmlElementEventArgs)
TextBox4.Text = e.ToElement.GetAttribute("href")
End Sub

Or:


That appears to be for an Awesomium WebBrowser control. That is not the same as the WebView2 control, but I'm not aware of what similarities and differences there are. Did you test that solution with a WebView2 control to see whether it actually addresses the OP's question?
 

Rythorian77

Member
Joined
Nov 23, 2021
Messages
17
Programming Experience
10+
That appears to be for an Awesomium WebBrowser control. That is not the same as the WebView2 control, but I'm not aware of what similarities and differences there are. Did you test that solution with a WebView2 control to see whether it actually address the OP's question?

That appears to be for an Awesomium WebBrowser control. That is not the same as the WebView2 control, but I'm not aware of what similarities and differences there are. Did you test that solution with a WebView2 control to see whether it actually address the OP's question?

I stand corrected, I'm glad you pointed this out to me, I was distracted earlier, but managed to do some research on the OP's question and made a new reply. Thank you for letting me know.
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,580
Location
Sydney, Australia
Programming Experience
10+
Rythorian77 , I write the program in VisualBasic not in Visual C

That would be C# rather than C, which is a different language. C# code can almost always be translated to VB.NET very easily. Even a beginner can do it for simple code, if they read it with an open mind. There are numerous online converters that have various levels of effectiveness that depend on the complexity of the code and how new the language features are that it uses. There is also Instant VB that you can download from Tangible Software Solutions and install locally. It is the best and most current converter that I have encountered.
 

Rythorian77

Member
Joined
Nov 23, 2021
Messages
17
Programming Experience
10+
Rythorian77 , I write the program in VisualBasic not in Visual C

I see, did you rename your document? I found this regarding Visual Basics. The issue for this person refers to the renaming of his "startup form" (which yours is documents), but it serves the same principle. If you go to this link and look below the code at the replied answers, it may help. I will keep researching this for you.

Also: You may already know this:
Note that you need to use webView2.CoreWebView2.Navigate(url) to navigate the WebView2 to the URL.
 
Top Bottom