我有这段代码:
private void goButton_Click(object sender, EventArgs e)
{
web.Navigate(loginURL.Text + "/auth/login");
}
我有浏览器显示,它只是没有导航......它没有导航等。
网址有效。
答案 0 :(得分: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
}
答案 1 :(得分: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;
}
}