0

我有这个代码:

private void goButton_Click(object sender, EventArgs e)
{
    web.Navigate(loginURL.Text + "/auth/login");
}

我有浏览器显示,它只是没有导航......它没有导航等。

URL 有效。

4

2 回答 2

1

您需要处理DocumentCompleted网络浏览器的事件。

通过以下代码:

  private void goButton_Click(object sender, EventArgs e)
    {
      WebBrowser wb = new WebBrowser();
      wb.AllowNavigation = true;

      wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(wb_DocumentCompleted);

      wb.Navigate(loginURL.Text + "/auth/login");

              }

    private void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
      WebBrowser wb = sender as WebBrowser;
      // wb.Document is not null at this point
    }
于 2013-08-05T04:56:43.470 回答
1

MSDN是你的朋友。确保您有“http://”前缀并尝试使用Navigate(Uri url)重载。

// Navigates to the given URL if it is valid. 
private void Navigate(String address)
{
    if (String.IsNullOrEmpty(address)) 
         return;

    if (address.Equals("about:blank")) 
         return;

    if (!address.StartsWith("http://") && !address.StartsWith("https://"))
    {
        address = "http://" + address;
    }
    try
    {
        webBrowser.Navigate(new Uri(address));
    }
    catch (System.UriFormatException)
    {
        return;
    }
}
于 2013-08-05T08:37:41.997 回答