[英]Wait for webBrowser control to fully load
I am currently working with a webBrowser control in a WinForm
- 我目前正在
WinForm
使用webBrowser控件 -
public Form1()
{
InitializeComponent();
webBrowser1.AllowNavigation = true;
webBrowser1.Navigate("http://foo.bar");
}
I have a button control that takes the webBrowser1.Url.OriginalString
and sets it to a textBox - 我有一个按钮控件,它接受
webBrowser1.Url.OriginalString
并将其设置为textBox-
// On button_Click
string requestResponse = webBrowser1.Url.OriginalString;
requestURLtextBox.Text = requestResponse;
However if the button is clicked before webBrowser1
has had enough time to get the OriginalString
text, this will error as the value does not exist yet. 但是,如果在
webBrowser1
有足够的时间获取OriginalString
文本之前单击该按钮,则此错误将出错,因为该值尚不存在。
I tried adding - 我尝试添加-
while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
{
Thread.Sleep(1000);
}
Before the previous code in the button_Click event however this went into an infinite loop. 但是,在button_Click事件中的先前代码之前,这陷入了无限循环。 How can I retrieve the
OriginalString
after the webBrowser is complete? webBrowser完成后如何检索
OriginalString
?
Here some VB simple code that may work for you: 以下是一些可能适合您的VB简单代码:
If mbBusy Then Exit Function ' form level variable
mbBusy = True
Web.Navigate("http://.....htm")
dtWebWait = Now().AddSeconds(timeoutSeconds)
Do Until Web.ReadyState = WebBrowserReadyState.Complete
Application.DoEvents()
If Now() > dtWebWait Then
MsgBox("navigate timeout - search form")
Exit Function
End If
Threading.Thread.Sleep(250)
Loop
mbBusy = False
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.