WebBrowser, right click on links to open new tab - vb.net

I have made this code to open new TABs, if I click "right click" on links then I choose "open in new window"
it's open a new TAB in my browser but at the same time Internet Explorer will be opened too.
I just want to make the IE silent, or making new tab option not gray to use it. I don't want to make my custom menu, I am sure there is a solution for this.
I have searched on my question here it's different problem so please it's not duplicate
This is what I have used to make that works
Private Sub WebBrowser1_NewWindow1(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles WebBrowser1.NewWindow
Dim Browser As New WebBrowser
TabControl1.TabPages.Add("New Page")
TabControl1.SelectTab(int)
Browser.Name = "Web Browser"
Browser.Dock = DockStyle.Fill
TabControl1.SelectedTab.Controls.Add(Browser)
AddHandler Browser.ProgressChanged, AddressOf Loading
AddHandler Browser.DocumentCompleted, AddressOf Done
int = int + 1
End Sub

I solve it.
It's simple this command line will make IE silent.
e.Cancel = True
You don't need to build other menu and turn off the main menu of the IE then build all Items again.
This is the final code to open links when you click "right click on them" and will be opened in a new tab
Private Sub WebBrowser1_NewWindow1(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles WebBrowser1.NewWindow
e.Cancel = True
Dim thiselement As HtmlElement = WebBrowser1.Document.ActiveElement
Dim Browser As New WebBrowser
Dim targeturl As String = thiselement.GetAttribute("href")
With Browser
.Navigate(targeturl)
.Dock = DockStyle.Fill
End With
TabControl1.TabPages.Add(targeturl)
TabControl1.SelectTab(int)
TabControl1.SelectedTab.Controls.Add(Browser)
AddHandler Browser.ProgressChanged, AddressOf Loading
AddHandler Browser.DocumentCompleted, AddressOf Done
int = int + 1
End Sub

Related

InvokeMember("click") does not trigger WebBrowser.DocumentCompleted event

This old unresolved question seems to relate most to my issue WebBrowser control not responding to InvokeMember("click")
The main difference is where the conversation petered out, my webpage does respond to ContentPlaceHolder1_btnComtrsView.click() correctly, where in the original question it did not.
I am trying to pull up a lat/long result after clicking the "View" button after entering in a value for COMTRS (use "M11S19E20" for example): https://www.earthpoint.us/TownshipsCaliforniaSearchByDescription.aspx
I've got the 2 separate document completed event handlers working correctly and all of that. So is it possible to handle the event of the document updating after clicking view? My code does work if I just click once to load the page and click, and a second time to pull the data out.
WebBrowserTRS.ScriptErrorsSuppressed = True
AddHandler WebBrowserTRS.DocumentCompleted, AddressOf ClickViewButton
WebBrowserTRS.Navigate("https://www.earthpoint.us/TownshipsCaliforniaSearchByDescription.aspx")
Private Sub ClickViewButton(sender As Object, e As WebBrowserDocumentCompletedEventArgs)
If e.Url.ToString() = "about:blank" Then Return
RemoveHandler WebBrowserTRS.DocumentCompleted, AddressOf ClickViewButton
Dim trsDoc As HtmlDocument = WebBrowserTRS.Document
Dim elem_Input_Submit As HtmlElement = trsDoc.GetElementById("ContentPlaceHolder1_btnComtrsView")
trsDoc.GetElementById("ContentPlaceHolder1_Comtrs").InnerText = _comtrs
AddHandler WebBrowserTRS.DocumentCompleted, AddressOf GetLatLong
elem_Input_Submit.InvokeMember("click")
End Sub
Private Sub GetLatLong(sender As Object, e As WebBrowserDocumentCompletedEventArgs)
RemoveHandler WebBrowserTRS.DocumentCompleted, AddressOf GetLatLong
Dim trsDoc As HtmlDocument = WebBrowserTRS.Document
Dim centroidFound As Boolean = False
For Each el As HtmlElement In trsDoc.GetElementsByTagName("tr")
Dim val As String
For Each el1 As HtmlElement In el.GetElementsByTagName("TD")
val = el1.InnerText
If val IsNot Nothing AndAlso val.Contains("Centroid") Then
centroidFound = True
' ...
WebBrowserTRS = New WebBrowser
Return
End If
Next
Next
If Not centroidFound Then
MsgBox("Unable to parse the township and range.",
MsgBoxStyle.Information, "Error in location lookup")
End If
Cursor = Cursors.Default
toolstripViewMap.Enabled = True
End Sub

VB.NET | Cannot duplicate tabs properly

I'm trying to create a browser in VB.NET, but I'm having problems to create a button that can "duplicate tabs" in my tabcontrol (called Child_TabControl). Well, I have this code and it seems to works fine in the first tab, but when I try to click on the duplicate button in the generated tab, it duplicates again the URL in the first tab. Anyone can help me to solve this?
Private Async Sub Btn_Duplicate_Click(sender As Object, e As EventArgs) Handles Btn_Duplicate.Click
Dim newTab As New TabPage
Dim child_header As New Tabs_Child_Header
Dim browser As New WebView2
'Events
Await browser.EnsureCoreWebView2Async
AddHandler browser.CoreWebView2.NewWindowRequested, AddressOf Browser_NewWindowRequested
AddHandler browser.CoreWebView2.NavigationCompleted, Sub()
child_header.Text_Url.Text = browser.Source.AbsoluteUri
End Sub
AddHandler child_header.Btn_Back.Click, Sub()
browser.GoBack()
End Sub
AddHandler child_header.Btn_Foward.Click, Sub()
browser.GoForward()
End Sub
AddHandler child_header.Btn_Update.Click, Sub()
browser.Reload()
End Sub
AddHandler child_header.Btn_Duplicate.Click, AddressOf Btn_Duplicate_Click
'Load Child
Child_TabControl.TabPages.Add(newTab)
child_header.TopLevel = False
child_header.Visible = True
child_header.Dock = DockStyle.Fill
newTab.Controls.Add(child_header)
'Child_TabControl.SelectTab(newTab)
'Load Webview
newTab.Text = Child_TabControl.SelectedTab.Text
child_header.Panel_Navigate.Controls.Add(browser)
browser.Dock = DockStyle.Fill
browser.Visible = True
browser.Source = New Uri(Text_Url.Text)
End Sub
I don't know how to reference (as Me) to my control Tabs_Child_Header dinamically created previously.

How to open a new web browser window in a tab control vb.net

I am working on a project that includes web browser functionality, but the problem is when a javascript command creates a new tab/new window, it opens in a new IE window.
(Please note: I am NOT talking about clicking a link to make a new window, its in the javascript)
The code I have creates the new tab and a new web browser, but it does not load the web page. How would I do so?
Private Sub WebBrowser1_NewWindow(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles WebBrowser1.NewWindow
Dim wb As New WebBrowser
Label3.Text = "Flagged New Window"
'make tab control page
e.Cancel = True
Dim myTabPage As New TabPage()
myTabPage.Text = "New Page" & (TabControl1.TabPages.Count + 1)
TabControl1.TabPages.Add(myTabPage)
'
Label3.Text = "Created Tab Control"
'insert new web browser control into the new page
Label3.Text = "Inserted web browser control"
'suppress errors
'WebBrowser1.ScriptErrorsSuppressed = True;
Label3.Text = "Suppressed Errors"
'Get page
myTabPage.Controls.Add(wb)
wb.Navigate(sender.Url)
End Sub

WebBrowser Visual Basic

How do I stop a new tab from opening google.com automaticaly in visual basic. I need a blank url textbox
This is my code for new tab
Private Sub AddTabToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles AddTabToolStripMenuItem.Click
Dim tab As New TabPage
Dim newtab As New tab
newtab.Show()
newtab.TopLevel = False
newtab.Dock = DockStyle.Fill
tab.Controls.Add(newtab)
Form1.TabControl1.TabPages.Add(tab)
Form1.TabControl1.SelectedTab = tab
And this is the code when form loads
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim t As New TabPage
Dim newtab As New tab
newtab.Show()
newtab.TopLevel = False
newtab.Dock = DockStyle.Fill
t.Controls.Add(newtab)
TabControl1.TabPages.Add(t)
End Sub
If you wanted you could allow the user to set their own homepage.
Simply create a button, or an item in the drop down bar that says "Set Homepage"
Create a new setting for your web browser called homePage, set it to string. Do nothing else.
Next create a new form called Homepage and link it to the button you created in step one by double clicking the button and putting
homepage.show()
in the code for that button.
On the other form you created you need a text box, and a button that says save.
double click the button and put this code in the button's code block.
textbox1.text = my.settings.homePage
my.settings.save()
Finally on your original browser form, under form1_load put this line of code
webbrowser1.navigate(my.settings.homePage)
That should work, it did for my browser at least
It won't open a page until you actually set it to open a page. Somewhere in your code you have something that will look similar to
webbrowser1.navigate("www.google.com")
Most likely within your form_load event. Just delete that.

WebBrowser Control (VB.NET) new tab

I have a problem with WebBrowser Control in vb.net (Windows form application) . The problem is when i click on a hyperlink that opens it new tab , it opens new Internet Explorer window? How can I make to open new tab in my tab control instead of Internet Explorer ? I searched online , but i only found results for c# . For example this result Open link in new TAB (WebBrowser Control)
The code in question from the other link.........
Private Sub InitializeBrowserEvents(SourceBrowser As ExtendedWebBrowser)
SourceBrowser.NewWindow2 += New EventHandler(Of NewWindow2EventArgs)(AddressOf SourceBrowser_NewWindow2)
End Sub
'
Private Sub SourceBrowser_NewWindow2(sender As Object, e As NewWindow2EventArgs)
Dim NewTabPage As New TabPage() With { Key .Text = "Loading..." }
Dim NewTabBrowser As New ExtendedWebBrowser() With { Key .Parent = NewTabPage, Key .Dock = DockStyle.Fill, Key .Tag = NewTabPage }
'
e.PPDisp = NewTabBrowser.Application
InitializeBrowserEvents(NewTabBrowser)
'
Tabs.TabPages.Add(NewTabPage)
Tabs.SelectedTab = NewTabPage
End Sub
'
Private Sub Form1_Load(sender As Object, e As EventArgs)
InitializeBrowserEvents(InitialTabBrowser)
End Sub
Please note, I used THIS link to convert code...
http://www.developerfusion.com/tools/convert/csharp-to-vb/?batchId=2183e979-2b56-4c82-a7d5-c0822e7f0bca
The easiest solution is to add my Tabbed_EI .dll to your tool box and link your application button clicks and other events to Tabbed_EI's public/global variables, objects, and Subs. Located here
You can otherwise use the Webbrowser.newWindow event and add
"e.cancel = true"