5 Replies - 831 Views - Last Post: 15 January 2013 - 04:16 PM Rate Topic: -----

#1 iamcpc  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 15-January 13

VS 2008 multiple form and webbrowser question

Posted 15 January 2013 - 02:22 PM

I have a webbrowser1 on form1.

I want a user to click a button on form4 and have it navigate webbrowser1 from www.google.com to www.yahoo.com and then after the navigation is complete do something else.


The problem is that when I navigate webbrowser1 it does not navigate unless a messagebox pops up. this is my form4 buttonclick code. I tried using the webbrowser navigate completed event and creating a webbrowser while busy loop and neither worked because the webbrowser does not navigate.


'webbrowser1 url is currently www.yahoo.com

If Not Form1.WebBrowser1.Url.ToString Like "*google*" Then
Form1.WebBrowser1.Navigate("http://www.google.com/")
end if


Debug.Print(Form1.WebBrowser1.Url.ToString)
'shows yahoo.com because the webbrowser1 has not navigated
'if I wait for the navigate completed event i'll wait forever because the navigate has not started

MsgBox("done")
'this msgbox appears to be making the webbrowser navigate
'which then does my webbrowser while busy loop and fires the webbrowser1 navigate completed event

Debug.Print(Form1.WebBrowser1.Url.ToString)
'only after the msgbox was displayed is the url now www.google.com




how can i get the webbrowser from another form to navigate without having the user click on a msgbox?

Is This A Good Question/Topic? 0
  • +

Replies To: VS 2008 multiple form and webbrowser question

#2 andrewsw  Icon User is offline

  • It's just been revoked!
  • member icon

Reputation: 3734
  • View blog
  • Posts: 13,054
  • Joined: 12-December 12

Re: VS 2008 multiple form and webbrowser question

Posted 15 January 2013 - 02:38 PM

The Navigate method expects an Uri object, rather than a string:

Form1.WebBrowser1.Navigate(New Uri("http://www.google.com/"))

although, in which case, it's a little surprising that it works on a second attempt (after the MsgBox).

This post has been edited by andrewsw: 15 January 2013 - 02:39 PM

Was This Post Helpful? 0
  • +
  • -

#3 NathanMullenax  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 86
  • View blog
  • Posts: 189
  • Joined: 23-September 12

Re: VS 2008 multiple form and webbrowser question

Posted 15 January 2013 - 02:39 PM

The document isn't actually loaded until the DocumentCompleted event is fired.

This
<a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.documentcompleted.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1">MSDN page</a>
shows how to register an event listener in VB. Hope this helps.
Was This Post Helpful? 0
  • +
  • -

#4 iamcpc  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 15-January 13

Re: VS 2008 multiple form and webbrowser question

Posted 15 January 2013 - 02:45 PM

View Postandrewsw, on 15 January 2013 - 02:38 PM, said:

The Navigate method expects an Uri object, rather than a string:

Form1.WebBrowser1.Navigate(New Uri("http://www.google.com/"))

although, in which case, it's a little surprising that it works on a second attempt (after the MsgBox).



I tried making it a new uri and it's still the same problem. The webbrowser on form1 is not navigated until after the other form pops up a msgbox.
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw  Icon User is offline

  • It's just been revoked!
  • member icon

Reputation: 3734
  • View blog
  • Posts: 13,054
  • Joined: 12-December 12

Re: VS 2008 multiple form and webbrowser question

Posted 15 January 2013 - 03:03 PM

I just ran a quick test and it worked okay for me:

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim frm2 As New Form2
        frm2.Show()
        frm2.WebBrowser1.Navigate(New Uri("http://www.google.com"))

    End Sub


There must be something else preventing the the form from refreshing/ accepting the instruction until focus leaves your currernt form. I suppose you might try:

Form1.WebBrowser1.Refresh()
Was This Post Helpful? 0
  • +
  • -

#6 iamcpc  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 15-January 13

Re: VS 2008 multiple form and webbrowser question

Posted 15 January 2013 - 04:16 PM

View Postandrewsw, on 15 January 2013 - 03:03 PM, said:

I just ran a quick test and it worked okay for me:

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim frm2 As New Form2
        frm2.Show()
        frm2.WebBrowser1.Navigate(New Uri("http://www.google.com"))

    End Sub


There must be something else preventing the the form from refreshing/ accepting the instruction until focus leaves your currernt form. I suppose you might try:

Form1.WebBrowser1.Refresh()


It's the same problem. The webbrowser does not navigate until the button click sub has completed or a msgbox pops up.

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim frm1 As New Form1
        frm1.Show()
        frm1.WebBrowser1.Navigate(New Uri("http://www.yahoo.com"))
        frm1.WebBrowser1.Navigate("http://www.yahoo.com")
        frm1.WebBrowser1.Refresh()
        'On Error Resume Next
        Debug.Print(frm1.WebBrowser1.Url.ToString)

        'On Error GoTo 0


        MsgBox("done")
        Debug.Print(frm1.WebBrowser1.Url.ToString)

    End Sub





it's the same problem the navigate or url change does not go until the messagebox pops up or the sub ends. What can I do to enable form 2 to navigate form1.webbrowser1 without ending the sub or having a messagebox pop up?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1