WebBrowser Visual Basic - vb.net

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.

Related

vb.net web browser new tab or new window on right click

i have made a web browser in vb.net 2013 and whenever i right click on a link and press new window it takes me to IE new window, i want it to open in my own new window, and plus i want to have a new tab option on right click too thaaaanks in advance, im new at this so anything is ok... this is my code for new tab and window respectively...
Public Sub addTab(ByRef tabControl As TabControl)
Dim browser As New webBrowserFunction
Dim tab As New TabPage
browser.Tag = tab
tab.Tag = browser
TabControl1.TabPages.Add(tab)
tab.Controls.Add(browser)
browser.Dock = DockStyle.Fill
browser.Navigate(My.Settings.HomePage)
TabControl1.SelectedTab = tab
End Sub
Private Sub NewWindowToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles NewWindowToolStripMenuItem.Click
Dim newWindow As New frmVortex
newWindow.Show()
End Sub
Webbrowser control doesn't support multiple tabs, but if you want to make new tabs you should use tab control with multiple webbrowser controls, check this: https://social.msdn.microsoft.com/Forums/vstudio/en-US/785637ac-a920-4592-974c-bf9b7ac03b7f/creating-a-multi-tabbed-browser-using-webbrowser-control-in-c?forum=csharpgeneral

Visual Basic Dynamically Create and Erase Controls

I use Visual Basic in Visual Studio 2015 and i am trying when i click on a StripMenu to appear me some TextBoxes and Buttons.
After another click in Stripmenu i want to erase them and add new one.
My problem is in Erase (delete or clear my buttons and textboxes) controls from my surface.
I try to do it use Button.Visible =True (or False) but it's not seems to be really helpful in a big amount of controls.
Private Sub ClassAToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ClassAToolStripMenuItem.Click
Label1.Text = "Sum A class Students: "
Dim btnA As Button = New Button
btnA.Location = New Point(420, 180)
btnA.Name = "Btn1"
btnA.Text = "OK"
btnA.Visible = True
Me.Controls.Add(btnA)
AddHandler btnA.Click, AddressOf button
End Sub
Private Sub button()
'What my Button does.
End Sub
I create dynamically through this code my Button but if i want to go in another Menu option i want to erase this button to add again my new controls (such us new buttons labels etc).
Your declaration is out of scope since you declared it in the menu's click method. You would have to use the Find method to get back the reference to the control you created:
Dim btn = Me.Controls.Find("Btn1", True).FirstOrDefault()
If btn IsNot Nothing Then
btn.Dispose()
End If
If you are trying to replace the contents of a panel with a new "screen" on your menu click, you can try code like this:
While Panel1.Controls.Count > 0
Panel1.Controls(0).Dispose()
End While
Dim newControl As New UserControl1
newControl.Dock = DockStyle.Fill
Panel1.Controls.Add(newControl)

hide winform when application loses focus

I have a winform that I use to navigate through my excel workbook. The form opens on the Workbook Open event. All works fine, but I just noticed that if my application is open and I open any other, say IE, my winform remains on top and does not hide. Is there a way to tell my form to hide when my workbook or the application lose focus?
I have searched MSDN and the web and could not really find anything?
Private Sub NavigationForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'This procedure runs when the form loads. The procedure displays
'the form on the upper left hand corner of the main screen.
'It also disables and hids the btnHideForm button.
Me.Location = New Point(0, 0)
With btnHideForm
.Visible = True
.Enabled = True
End With
End Sub
Public Class ThisWorkbook
Private Sub ThisWorkbook_Startup() Handles Me.Startup
Dim navForm As New frmNavigation
navForm.Show()
End Sub
This is the code running on form load and on the workbook open

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.

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"