Results 1 to 2 of 2

Thread: [RESOLVED] Send a string to a new WPF Window with a webbrowser control

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Location
    Burlington, ON, Canada
    Posts
    343

    Resolved [RESOLVED] Send a string to a new WPF Window with a webbrowser control

    Hi guys,

    I have a customer form that contains addresses on it for each individual customer, i have a "Map" button with the following code:

    Code:
    Private Sub btnMap_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnMap.Click
            Try
                Dim street As String = String.Empty
                Dim city As String = String.Empty
                Dim state As String = String.Empty
                Dim zip As String = String.Empty
                Dim username, password As String
                username = DirectCast(win, loginform2).defaultproxyserverusername
                password = DirectCast(win, loginform2).defaultproxyserveruserpassword
    
                Dim queryAddress As New StringBuilder()
                queryAddress.Append("http://" + username + ":" + password + "@" + "maps.google.com/maps?q=")
                ' build street part of query string
                If tbAddress.Text <> String.Empty Then
                    street = Trim(tbAddress.Text).Replace(" ", "+")
                    queryAddress.Append(street + "," & "+")
                End If
                ' build city part of query string
                If tbCity.Text <> String.Empty Then
                    city = Trim(tbCity.Text).Replace(" ", "+")
                    queryAddress.Append(city + "," & "+")
                End If
                ' build state part of query string
                If tbProvinceState.Text <> String.Empty Then
                    state = Trim(tbProvinceState.Text).Replace(" ", "+")
                    queryAddress.Append(state + "," & "+")
                End If
                ' build zip code part of query string
                If tbPostalZip.Text <> String.Empty Then
                    zip = Trim(tbPostalZip.Text).ToString()
                    queryAddress.Append(zip)
                End If
    
                ' pass the url with the query string to web browser control in a new window
                Dim f2 As New MapItForm()
                f2.WebBrowser1.NavigateToString(queryAddress.ToString)
                f2.Show()
    
            Catch ex As Exception
                MessageBox.Show(ex.Message.ToString(), "Unable to Retrieve Map, make sure you are online and/or the address is accurate", MessageBoxButton.OK, MessageBoxImage.Exclamation)
            End Try
    End Sub
    I'm trying to send the generated url to the new wpf window's webbrowser control and display the link.

    The window launches and shows the generated url text, but doesn't go to the page.

    any help would be appreciated.

    thx

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Location
    Burlington, ON, Canada
    Posts
    343

    Re: Send a string to a new WPF Window with a webbrowser control

    got it:

    Code:
    f2.WebBrowser1.Source = New Uri(queryAddress.ToString, UriKind.Absolute)
    gotta love the "just different enough" syntax of WPF.... :-) I also had to remove the username and password from the string above to be this:

    queryAddress.Append("http://" + "maps.google.com/maps?q=") instead of this:

    queryAddress.Append("http://" + username + ":" + password + "@" + "maps.google.com/maps?q=")

    hope this helps others...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width