Progress bar for a web browser control

徘徊边缘 提交于 2019-12-02 01:43:45

Look at the WebBrowser.ProgressChanged event.

The WebBrowser control has a ProgressChanged event:

You need to attach an event handler to the ProgressChanged event:

WebBrowser1.ProgressChanged += WebBrowser1_ProgressChanged;

This is shorthand for:

WebBrowser1.ProgressChanged += new WebBrowserProgressChangedEventHandler(WebBrowser1_ProgressChanged);

The compiler will infer the handler and add that at compile time.

Next, implement the handler:

private void WebBrowser1_ProgressChanged(object sender, WebBrowserProgressChangedEventArgs e) {
    ProgressBar1.Value = e.CurrentProgress;
}

The WebBrowserProgressChangedEventArgs type supports a CurrentProgress property which reflects the current state of the browser control's progress.

Use WebBrowser.ProgressChanged Event, but to report the progress use the code below:

private void WebBrowser1_ProgressChanged(Object sender, 
                                         WebBrowserProgressChangedEventArgs e)
{
    progressBar.Maximum = (int) e.MaximumProgress;
    if (e.CurrentProgress > 0)
       progressBar.Value = (int) e.CurrentProgress;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!