WebBrowser.ProgressChanged 事件


WebBrowser 控件已更新有关要导航到的文档的下载进度的信息时发生。Occurs when the WebBrowser control has updated information on the download progress of a document it is navigating to.

 event System::Windows::Forms::WebBrowserProgressChangedEventHandler ^ ProgressChanged;
public event System.Windows.Forms.WebBrowserProgressChangedEventHandler ProgressChanged;
member this.ProgressChanged : System.Windows.Forms.WebBrowserProgressChangedEventHandler 
Public Custom Event ProgressChanged As WebBrowserProgressChangedEventHandler 


下面的代码示例演示如何使用此成员。The following code example demonstrates the use of this member. 在此示例中, 事件处理程序报告ProgressChanged事件的发生。In the example, an event handler reports on the occurrence of the ProgressChanged event. 此报表可帮助你了解何时发生事件, 并可帮助你进行调试。This report helps you to learn when the event occurs and can assist you in debugging. 若要报告多个事件或频繁发生的事件, 请考虑MessageBox.ShowConsole.WriteLine消息替换为多行或将TextBox其追加到多行。To report on multiple events or on events that occur frequently, consider replacing MessageBox.Show with Console.WriteLine or appending the message to a multiline TextBox.

若要运行示例代码, 请将其粘贴到包含名为WebBrowser WebBrowser1的类型的实例的项目中。To run the example code, paste it into a project that contains an instance of type WebBrowser named WebBrowser1. 然后, 确保事件处理程序与ProgressChanged事件相关联。Then ensure that the event handler is associated with the ProgressChanged event.

private void WebBrowser1_ProgressChanged(Object sender, WebBrowserProgressChangedEventArgs e) {

System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
messageBoxCS.AppendFormat("{0} = {1}", "CurrentProgress", e.CurrentProgress );
messageBoxCS.AppendFormat("{0} = {1}", "MaximumProgress", e.MaximumProgress );
MessageBox.Show(messageBoxCS.ToString(), "ProgressChanged Event" );
Private Sub WebBrowser1_ProgressChanged(sender as Object, e as WebBrowserProgressChangedEventArgs) _ 
     Handles WebBrowser1.ProgressChanged

    Dim messageBoxVB as New System.Text.StringBuilder()
    messageBoxVB.AppendFormat("{0} = {1}", "CurrentProgress", e.CurrentProgress)
    messageBoxVB.AppendFormat("{0} = {1}", "MaximumProgress", e.MaximumProgress)
    MessageBox.Show(messageBoxVB.ToString(),"ProgressChanged Event")

End Sub


可以使用此事件的处理程序来实现类似于 Internet Explorer 中的导航进度栏。You can use a handler for this event to implement a navigation progress bar similar to the one in Internet Explorer. WebBrowserProgressChangedEventArgs.CurrentProgress使用属性来确定已成功下载的字节数。Use the WebBrowserProgressChangedEventArgs.CurrentProgress property to determine the number of bytes that have been downloaded successfully. WebBrowserProgressChangedEventArgs.MaximumProgress使用属性来确定可供下载的总字节数。Use the WebBrowserProgressChangedEventArgs.MaximumProgress property to determine the total number of bytes available for downloading.

有关处理事件的详细信息, 请参阅处理和引发事件For more information about handling events, see Handling and Raising Events.


供直接调用方使用此控件。for immediate callers to use this control. 要求值: LinkDemand;命名权限集: FullTrustDemand value: LinkDemand; Named Permission Sets: FullTrust.