Open a webpage as soon as Webbrowser1 changes page? - vb.net

I'm starting out coding and I've encountered a problem in the VB.NET application I'm creating.
When a new webpage is loaded in Webbrowser1 I want my code to open a link to execute in your own webbrowser, i.e chrome, Firefox.
How would I go about doing this?

Public Class Form1
Dim FirstRun As Boolean = True
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
WebBrowser1.Navigate("http://stackoverflow.com")
End Sub
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
If Not FirstRun Then Process.Start("http://stackoverflow.com")
FirstRun = False
End Sub
End Class

Related

How do you open an already disposed form in VB?

When I close Form2 it won’t open up again after.
I am using a button click to open up another form. Right now I just have:
Dim Form2 As New Form2
Private Sub btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn.Click
Form2.Show()
End Sub
Now whenever I close the form I cannot open it again.
Like this
Private MyForm2 As Form2
Private Sub btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn.Click
If MyForm2 Is Nothing OrElse MyForm2.IsDisposed Then
MyForm2 = New Form2
End If
MyForm2.Show()
End Sub

How Do I Click This Button? In Visual Basic 2010 WebBrowser control

I am trying to click this button in WebBrowser Control
Im trying to make a web automation to purchase from gamestop im using visual basic 2010 express heres what my code looks like
Public Class Form1
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
WebBrowser1.Document.GetElementById("mainContentPlaceHolder_dynamicContent_ctl00_RepeaterResultFoundTemplate_ResultFoundPlaceHolder_1_ctl00_1_ctl00_1_StandardPlaceHolderTop_3_ctl00_3_rptResults_3_res_0_btnAddToCart_0").InvokeMember("Click")
End Sub
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
WebBrowser1.Navigate("http://www.gamestop.com/browse?nav=16k-3-wwii,28zu0")
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
WebBrowser1.Document.GetElementById("cartcheckoutbtn").InvokeMember("Click")
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
WebBrowser1.Document.GetElementById("buyasguest").InvokeMember("Click")
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
WebBrowser1.Document.GetElementById("ShipTo_FirstName").SetAttribute("value", "Rob")
WebBrowser1.Document.GetElementById("ShipTo_LastName").SetAttribute("value", "Horton")
WebBrowser1.Document.GetElementById("ShipTo_City").SetAttribute("value", "San Diego")
WebBrowser1.Document.GetElementById("USStates").InvokeMember("Select")
WebBrowser1.Document.GetElementById("ShipTo_Line1").SetAttribute("value", "9295 PebbleStone Ln")
WebBrowser1.Document.GetElementById("ShipTo_PostalCode").SetAttribute("value", "92128")
WebBrowser1.Document.GetElementById("ShipTo_PhoneNumber").SetAttribute("value", "6194682282")
For Each ee As HtmlElement In WebBrowser1.Document.All
If ee.InnerText Is Nothing Then Continue For
If ee.InnerText = "California" Then ee.SetAttribute("Selected", True)
Next
WebBrowser1.Document.GetElementById("ShipTo_EmailAddress").SetAttribute("value", TextBox1.Text)
For Each element As HtmlElement In WebBrowser1.Document.GetElementsByTagName("input")
If element.GetAttribute("class") = "btn_positive ats-checkoutbtn" Then
element.InvokeMember("click")
End If
Next
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Im trying to click on this button and i inspect elemented it and this is what showed up **
(CONTINUE CHECKOUT ▶)
**
How Do I make it click this i tried Id but it has no id
btw im new to this just trying to make a auto web automation software to purchase games The code thats there when i inspect element it is on the top top top
You are actually trying to click a link and not an input button.
The link has an onclick attribute that contains javascript and returns false.
So you can either find that link or you can just execute the Javascript that the link executes submitshipto()
WebBrowser1.InvokeScript("submitshipto()")
Or:
For Each element As HtmlElement In WebBrowser1.Document.GetElementsByTagName("a")
If element.GetAttribute("class") = "btn_positive ats-checkoutbtn" Then
element.InvokeMember("click")
End If
Next

Refresh or Redraw picturebox in VB.net

I'm trying to view youtube captcha in my vb application but I don't know how to refresh/redraw the picture box. The youtube captcha is in http://www.youtube.com/cimg and the captcha is changing everytime I refresh the page. How can I do that using button or timer in vb.net to change the captcha. Here is the code I used to load the captcha to picturebox.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
captchaBox.ImageLocation = "http://www.youtube.com/cimg"
End Sub
i try to use captchaBox.Refresh() but it's not working. I hope someone can help me. thx
Refresh just redraws the control, it doesn't retrieve the image again. You need to reset the ImageLocation property for it to work. For example with a timer:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
captchaBox.ImageLocation = "http://www.youtube.com/cimg"
Timer1.Enabled = True
Timer1.Interval = 1000
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
captchaBox.ImageLocation = "http://www.youtube.com/cimg"
End Sub
Try this:
Private Sub Form1_Load() Handles MyBase.Load
Timer1.Start()
PictureBox1.ImageLocation = "http://www.youtube.com/cimg"
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
PictureBox1.Image = Nothing
PictureBox1.ImageLocation = "http://www.youtube.com/cimg"
End Sub

Reacting to third-party application form events using vb.net

I would like to know how I should code my VB.net application to react to the form load event in a third-party application (also written in VB.net)
To test, I have created two basic programs, one with two forms (program A) and one (program B) that attempts to the listen to program A's appropriate form load event. I have tried using WithEvents but it does not get fired when Program's A second form loads.
Here is the code for Program A:
Public Class StartPage
Public WithEvents loadtimer As New System.Windows.Forms.Timer
Private Sub StartPage_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
loadtimer.Interval = 1000
loadtimer.Enabled = True
loadtimer.Start()
End Sub
Private Sub loadtimer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles loadtimer.Tick
loadtimer.Stop()
SystemStatus.Show()
End Sub
End Class
Public Class SystemStatus
Inherits StartPage
Private Sub StartPage_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.Label1.Text = "This is the form that I want to listen for the load event"
Me.loadtimer.Enabled = False
End Sub
End Class
Here is the code for Program B:
Imports Program_A
Public Class ListeningForm
Dim WithEvents testlisten As New Program_A.SystemStatus
Private Sub testlisten_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles testlisten.Load
Label1.Text = "SystemStatus form loaded"
End Sub
Private Sub ListeningForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Label1.Text = "Waiting for SystemStatus load event..."
End Sub
End Class
I am quite new when it comes to programming so maybe this is not even possible or I just haven't been understanding what I've been reading. In any case please enlighten me as to what my next course of action should be.
Thanks very much in advance,
theoleric
This will do what your asking.
Imports Program_A
Public Class ListeningForm
Dim WithEvents testlisten As New SystemStatus
Private Sub testlisten_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles testlisten.Load
' now this event will fire
Label1.Text = "SystemStatus form loaded"
End Sub
Private Sub ListeningForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Label1.Text = "Waiting for SystemStatus load event..."
' the load event will not fire until you call this
testlisten.Show()
End Sub
End Class

vb.net read txtfile and navigate to that site (own browser development)

I have built my own browser 9see attached code) however I would like to modify the code so that textbox1 reads a txt file at start and uses the contents of that text file to navigate to a URL of equal value to the text with in that text file. All this should happen at the launch of the web browser form.
Example of the text file contents would be http://www.testsite.com
Code as follows:
#Region "Webbrowser navigation"
Private Sub Go()
WebBrowser1.Navigate(TextBox1.Text)
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Go()
End Sub
Private Sub TextBox1_keydown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyCode = Keys.Enter Then
Go()
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
WebBrowser1.GoBack()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
WebBrowser1.GoForward()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
WebBrowser1.Stop()
End Sub
#End Region
how can I best do this?
In the event handler for the form's Load event, do something like this:
TextBox1.Text = File.ReadAllText("StartUrl.txt")
Go()
However, unless you have some good reason to use a text file, I would suggest something more flexible and standard such as XML. If you don't mind using the standard app.config file, just add one of those to your project and you can use the ConfigurationManager class to read the setting.