Question Making a web browser load multiple web pages.

trevor206

New member
Joined
Apr 20, 2010
Messages
4
Programming Experience
1-3
ok i have a program and i want it to visit a pre-set list of websites which will be in a richtextbox and i want it to visit all the sites in order BUT heres my problem that idk how to fix it will only load the last page of the list it will not load any other ones. :(

Heres my code for it to visit the websites
VB.NET:
  For i = 0 To RichTextBox1.Lines.Count - 1
            WebBrowser1.Navigate(RichTextBox1.Lines(i))

        Next

Please explain how the code works if you do help me.

(if you helping me requires me to use a listbox or anything else i can do that)
 
I would imagine that your code is loading through the web pages, but just really fast, too fast to load them fully. The web browser will then settle on the last page specified.

Try adding a pause:

VB.NET:
Threading.Thread.Sleep(5000)

Or a message box after the navigate to procedure in your loop to separate each page load.

Or you could enable the page to load the next in the list by clicking a button. I'm not sure if making your thread sleep will stop the web browser from loading.
 
I would imagine that your code is loading through the web pages, but just really fast, too fast to load them fully. The web browser will then settle on the last page specified.

Try adding a pause:

VB.NET:
Threading.Thread.Sleep(5000)

Or a message box after the navigate to procedure in your loop to separate each page load.

Or you could enable the page to load the next in the list by clicking a button. I'm not sure if making your thread sleep will stop the web browser from loading.
i've tried that all it does is stop the whole form from loading and the web browser stays the same.
 
VB.NET:
Public Class Form1
    Private i As Integer = 0
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        WebBrowser1.Navigate(RichTextBox1.Lines(i))
        i = +1
    End Sub
End Class

This will load each line one by one when button1 is clicked.

you could integrate:

VB.NET:
    Private Sub WebBrowser1_Navigated(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatedEventArgs) Handles WebBrowser1.Navigated

    End Sub

into your code and reload the next line once this event fires.
 
VB.NET:
Public Class Form1
    Private i As Integer = 0
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        WebBrowser1.Navigate(RichTextBox1.Lines(i))
        i = +1
    End Sub
End Class

This will load each line one by one when button1 is clicked.

you could integrate:

VB.NET:
    Private Sub WebBrowser1_Navigated(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatedEventArgs) Handles WebBrowser1.Navigated

    End Sub

into your code and reload the next line once this event fires.

i might be using the code u gave me wrong but it didn't work. I got no errors but it just loads the first page and stops.
 
I take it that you kept pressing th button when the page loaded?

Also, that you are using the control names that I have in that code?

Try using the web browsers navigated event.
 
I take it that you kept pressing th button when the page loaded?

Also, that you are using the control names that I have in that code?

Try using the web browsers navigated event.
No i tried setting the code on a timer and on a button and i only pressed the button 1 time no matter what.

Also idk how to use the web browser events very well(please help)

im kinda noob.
 
start a new project and add a button, a web browser and a rich text box.

To the form 1 code, add the button click event thats in the earlier post from me.

add a couple of full web addresses to the rich text box.

Start the project and click the button once, wait for the page to load, then click it again.

For the events, on the form design view, click on the web browser, on the properties task pane (usually to the right) there will be a little lightning bolt, click on that and all the events should be listed, then double click the "navigated" event and some code should pop into your form code. Here you can add whatever code you would like to run once a page is loaded.
 
instead of Threading.Thread.Sleep(5000) which freezes the form try making a wait function

Sub wait(ByVal interval As Integer)
Dim sw As New Stopwatch
sw.Start()
Do While sw.ElapsedMilliseconds < interval
Application.DoEvents()
Loop
sw.Stop()
End Sub

call : wait(1000)
 
Back
Top