VB.NET Gecko WebBrowser Link Click to get URL - vb.net

So I am trying to get the URL of a link that I click while using the Gecko WebBrowser. So if I were to click on a .DLL file in my directory (URL = File://C:/File.DLL) it would then give me the URL of what I clicked. I can right click on it and get the URL but I would like to just be able to click on it and get the URL. Thank you very much!

I just asked how the handle a click on html element in Gecko and maybe this can help you:
Private Sub browser_DomClick(ByVal sender As Object, ByVal e As Gecko.DomMouseEventArgs) Handles browser.DomClick
Dim element As Gecko.GeckoHtmlElement = e.Target.CastToGeckoElement
Dim url as String = element.GetAttribute("href")
End Sub
Declare
Friend WithEvents browser As Gecko.GeckoWebBrowser
if needed
Not tested!

Related

pop-up new tab in browser for displays another aspx page in vb.net

I need to open a pop-up new tab in browser for displays another aspx page After trigger button click event(Html5).
I have found many ways to do this in JavaScript, but haven't been able to find a way to do it using VB.Net.
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
//How to implement code
End Sub
Use window.open with _blank as a parameter. For example:
Dim s As String = "window.open('" & url & "', '_blank');"
Hope this helps!

Manipulate text in a loaded html-page of the Webbrowser control in the DocumentCompleted event (vb.net)

I already tried some solutions provided here, but I cannot get it to work. On my winform I have a webbrowser control which should load a webpage (aspx). In case the webpage isn't found, I want to let the user know that this page isn't found. To get this to work I use the following code:
Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
If (WebBrowser1.Document.Url.ToString().StartsWith("res:")) Then
Dim curDir As String = Directory.GetCurrentDirectory()
Dim Url As Uri = New Uri(String.Format("file:///{0}/Html/PageNotFound.html", curDir))
WebBrowser1.Navigate(Url)
End If
End Sub
This is working fine. The page PageNotFound.html is shown. However, I would like to provide the user with some additional information which I want to insert into the PageNotFound.html at realtime (i.e. using document.getElementById to manipulate a Label-tag). I just don't know how I can do this, or if it is even possible. Maybe I use the wrong event. something I also tried is:
With WebBrowser1
.Navigate("about:blank")
.Document.OpenNew(False)
.Document.Write(HtmlString)
.Refresh()
End With
Where the HtmlString contains a complete webform.(like: "")
Maybe someone put me the right direction? TIA

Visual Basic - Web browser load URLs from text

i am not so great with Visual basic, but i need some help on creating a web browser that would load several links import from a text file, and for the web browser to navigate to them. This is what i have so far
Dim link As String = OpenFileDialog2.FileName
Dim links As String = IO.File.ReadAllText(link)
MsgBox(links)
WebBrowser1.Navigate(links)
You help means a lot. Thank You.
The WebBrowser Control either will show the webpage in the Control which will limit you to one page, or you can tell it to open the pages in separate windows which will open an Internet Explorer window for each link. I also used the File.ReadAllLines Method in order to get an array of the Links so that you can iterate through the Web Pages . This works for me but might not be what you are wanting.
Public Class Form1
Dim wb As New WebBrowser
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim filename As String = "C:\temp\links.txt"
Dim links As String() = IO.File.ReadAllLines(filename)
For Each link As String In links
wb.Navigate(link, True)
Next
End Sub
Public Sub New()
InitializeComponent()
Controls.Add(wb)
wb.Dock = DockStyle.Fill
End Sub
End Class
My text file called Links.txt looks like this:
www.google.com
www.msdn.com
www.bing.com

how to automatically click search button in google visual basic . net

I have a form with textbox, button and a tabcontrol.
in the button I have this code :
[Dim browser As New WebBrowser()
TabPage1.Controls.Add(browser)
browser.Dock = DockStyle.Fill
browser.Navigate(New Uri("http://www.google.com"))]
The code above works, but I need to be able to search from my textbox and when I click the button it will take me to google and then automatically enter's the word I searched for in my textbox and then clicks the search on google button. I tried this but it does not work. Thanks
Dim textElement. As HtmlElement = browser.Document.All.GetElementsByName("q")(0)
textElement.SetAttribute("value", textbox.text")
Dim btnElement As HtmlElement = browser.Document.All.GetElementsByName("btnG")(0)
btnElement.InvokeMember("click")
I also needed to search in Google Browser with the text the User wanted and by adding the code below to the Button Click Event it did what I wanted.
Code:
Dim sInfo As New ProcessStartInfo("https://www.google.co.in/search?q=" & TXT_Entidade.Text)
Try
Process.Start(sInfo)
Catch ex As Exception
Process.Start("iexplore.exe", sInfo.FileName)
End Try
You'll need to set focus to the textElement before clicking the button.
textElement.Focus()
Otherwise, the page won't run the search apparently.
You can see this by trying the same basic steps you've got above in the Console window. They won't work until the field has had focus (from my testing).
(I also used the mshtml type library so that the click function was directly exposed in the full code below)
Imports mshtml
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
web.Navigate("http://www.google.com")
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim textElement As HtmlElement = web.Document.All.GetElementsByName("q")(0)
textElement.SetAttribute("value", TextBox1.Text)
textElement.Focus()
Dim btnElement As HTMLButtonElement =
CType(web.Document.All.GetElementsByName("btnG")(0).DomElement,
HTMLButtonElement)
btnElement.click()
End Sub
End Class
I think you can use this in your button click handler...
browser.navigate("https://www.google.co.in/search?q="+textbox.Text)
This will search Google for the text in your Text Box.
You can search without "automatically clicking the search button" and you do not have to set the value in the text element of the html. This works for me. Hope this helps.

How to open a Bing Maps from vb.net?

I would like to pass and address to and open Bing Maps from a vb.net app. Anywhere I can find an example of how to do this?
You're going to want to check out the Bing Maps Web Services SDK. It allows you to use Bing to Geocode (retrieve a location from an address) as well as Download Imagery Data. Another place for Bing developers information can be found here.
Edit: I just reread your question and I think you can do what you need using a simple string concatenation to create a url. This might work:
Dim MyURL As String
Dim Location As String
Location = "Pittsburgh, PA"
MyURL = "http://www.bing.com/maps/?v=2&where1=" + HttpUtility.UrlEncode(Location) + "&encType=1"
System.Diagnostics.Process.Start(MyURL)
My VB is a little rusty, but this should get you started. You will also need to import the System.Web Namespace for the HttpUtility Class.
Refrences:
Launch Browser from VB.NET
HttpUtility.UrlEncode Method - MSDN
Bing URL Parameters
'In addition to kersney's example this uses the webbrowser control in a vb form
Imports System.Web
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Location As String = "Pittsburgh, PA"
Dim MyURL As String = "http://www.bing.com/maps/?v=2&where1=" + HttpUtility.UrlEncode(Location)
Dim WebBrowser1 As New WebBrowser
Me.WindowState = FormWindowState.Maximized 'maximize window
Me.Controls.Add(WebBrowser1) 'add browser control
WebBrowser1.Dock = DockStyle.Fill 'fill to form
WebBrowser1.Navigate(MyURL) 'display page in form
End Sub
Try the nerd dinner asp.net mvc tutorial. It's near the end and you can download a working example.