|
-
Jan 15th, 2013, 01:32 PM
#1
Thread Starter
Addicted Member
[RESOLVED] problems with navigating webbrowser on form1 from form2
I have webbrowser1 on form1.
I would like for a user to be able to click a button on form2 and have that button do two things
1. navigate form1.webbrowser1 from one document to another (for the sake of this lets just say www.google.com to www.yahoo.com)
2. after the webbrowser has navigated continue with the rest of the code
The problem is that the webbrowser will only navigate after the form2 button click is done or after i make a msgbox popup.
Why would the webrowser only navigate after a msgbox pops up?
an example of my form2.buttonclick event
form1.webbrowser1.navigate("www.yahoo.com")
debug.print form1.webbrowser1.url
'shows www.google.com
'i tried making a do while webbrowser1.readystate loop here but it goes forever because webbrowser1 never navigates
'i also tried using the form1.webrowser1 on navigate completed event but again it fails because webrowser1 never navigates.
msgbox ("this msgbox makes the webbrowser navigate")
debug.print form1.webbrowser1.url
'shows www.yahoo.com
-
Jan 15th, 2013, 04:04 PM
#2
Re: problems with navigating webbrowser on form1 from form2
It's not that the browser doesn't navigate. It's that your blocking the thread with your wait loop so it never shows the page. The msgbox doesn't have anything to do with anything. It just frees the thread to complete its task. If you're going to use a readystate loop at least allow the program to carry out its tasks ...
Form1.WebBrowser1.Navigate("www.yahoo.com")
While Form1.WebBrowser1.ReadyState <> WebBrowserReadyState.Complete
Me.Text = "Waiting"
Application.DoEvents()
End While
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Jan 15th, 2013, 04:05 PM
#3
Re: problems with navigating webbrowser on form1 from form2
In your form1, you'll have 3 events. The first is a button's click, the second is the webbrowser's document completed, and the third is the form load. In the button, you'll show form2. In the document completed you perform any code you want to perform after you visit a website. In the load, you simply navigate to yahoo.
Code:
Option Strict On
Option Explicit On
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Form2.Show()
End Sub
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
'Rest of the code once it's been navigated
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
WebBrowser1.Navigate("www.yahoo.com")
End Sub
End Class
In form2, you'll generate the button's click event. In that event you'll navigate form1's webbrowser:
Code:
Option Strict On
Option Explicit On
Public Class Form2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Form1.WebBrowser1.Navigate("www.google.com")
End Sub
End Class
-
Jan 16th, 2013, 08:26 AM
#4
Thread Starter
Addicted Member
Re: problems with navigating webbrowser on form1 from form2
 Originally Posted by dday9
In your form1, you'll have 3 events. The first is a button's click, the second is the webbrowser's document completed, and the third is the form load. In the button, you'll show form2. In the document completed you perform any code you want to perform after you visit a website. In the load, you simply navigate to yahoo.
Code:
Option Strict On
Option Explicit On
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Form2.Show()
End Sub
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
'Rest of the code once it's been navigated
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
WebBrowser1.Navigate("www.yahoo.com")
End Sub
End Class
In form2, you'll generate the button's click event. In that event you'll navigate form1's webbrowser:
Code:
Option Strict On
Option Explicit On
Public Class Form2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Form1.WebBrowser1.Navigate("www.google.com")
End Sub
End Class
This is not a solution. Let's just say that form2 will navigate form1.webbrowser1 and then, after that navigation is completed, put form2 in the yahoo search bar. I can't put the form2 into the yahoo search bar on every webbrowser1 navigate event because webbrowser1 will navigate away from yahoo and it starts on google and there will be an error when i try to put text into the yahoo search box and i'm on google.
-
Jan 16th, 2013, 08:41 AM
#5
Thread Starter
Addicted Member
Re: problems with navigating webbrowser on form1 from form2
 Originally Posted by dunfiddlin
It's not that the browser doesn't navigate. It's that your blocking the thread with your wait loop so it never shows the page. The msgbox doesn't have anything to do with anything. It just frees the thread to complete its task. If you're going to use a readystate loop at least allow the program to carry out its tasks ...
Form1.WebBrowser1.Navigate("www.yahoo.com")
While Form1.WebBrowser1.ReadyState <> WebBrowserReadyState.Complete
Me.Text = "Waiting"
Application.DoEvents()
End While
I can't do application.doevents() because application is ambiguous it's been imported from excel, outlook and windows forms.
-
Jan 16th, 2013, 09:24 AM
#6
Re: problems with navigating webbrowser on form1 from form2
And I suppose mine got overlooked ;]
-
Jan 16th, 2013, 07:44 PM
#7
Re: problems with navigating webbrowser on form1 from form2
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Jan 16th, 2013, 07:44 PM
#8
Thread Starter
Addicted Member
Re: problems with navigating webbrowser on form1 from form2
 Originally Posted by dday9
And I suppose mine got overlooked ;]
No it didn't get overlooked the problem is that i wanted form4 to be the only one to run the code after it navigated form1.webrowser1.
form4 navigates form1 to google and fills out the google search box or form4 navigates form1 to yahoo and fills out the yahoo search box. If i put the filling out of the searchbox on form1.webbrowser1.navigatecomplete event then if the user navigates to www.cnn.com the form will try to fill out a yahoo or google search box where there is none.
I found a workaround which involved making a wait function in a module and calling the wait function. the wait function was a combination of sleeping the thread and application.doevents() this solved all my problems. How do I mark this thread as resolved?
Last edited by iamcpc; Jan 16th, 2013 at 07:50 PM.
Reason: error
-
Jan 16th, 2013, 07:45 PM
#9
Re: problems with navigating webbrowser on form1 from form2
How do I mark this thread as resolved?
Thread Tools up the top of the page.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Jan 29th, 2013, 07:10 PM
#10
Thread Starter
Addicted Member
Re: problems with navigating webbrowser on form1 from form2
Is there any way that I can mark this thread as unsolved because application.doevents() wound up causing a lot of headache.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|