Progress bar for a web browser control

前端 未结 3 894
别那么骄傲
别那么骄傲 2021-01-21 07:39

How can I put, and use, a progress bar for my web browser control, in a windows application project, using the c# language?

相关标签:
3条回答
  • 2021-01-21 08:01

    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.

    0 讨论(0)
  • 2021-01-21 08:18

    Look at the WebBrowser.ProgressChanged event.

    0 讨论(0)
  • 2021-01-21 08:23

    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;
    }
    
    0 讨论(0)
提交回复
热议问题