c#webbrowser 判断是否能打开网页

2024-11-01 01:43:44
推荐回答(1个)
回答1:

private void button1_Click(object sender, EventArgs e)

{

wb.Url = new Uri("http://www.baidu.com");

wb.DocumentCompleted+=new WebBrowserDocumentCompletedEventHandler(wb_DocumentCompleted);

//这是给wb添加载入完毕的事件

}

private void wb_DocumentCompleted(object sender, EventArgs e)//这个就是当网页载入完毕后要进行的操作

{

这个就是当网页载入完毕后要进行的操作

}

+++++++++++++++++++++++++++++++++++++++++

webbrowser等待页面加载完毕

while (webBrowser1.IsBusy)
{
StartKiller();
MessageBox.Show("程序忙,请稍后!", "提示");

}

或者(不能用在线程中)

while (webBrowser1.ReadyState == WebBrowserReadyState.Complete)
{
StartKiller();
MessageBox.Show("程序忙,请稍后!", "提示");

}