PictureBox.LoadCompleted 事件

定义

在异步图像加载操作完成、取消或引发异常时发生。Occurs when the asynchronous image-load operation is completed, been canceled, or raised an exception.

public:
 event System::ComponentModel::AsyncCompletedEventHandler ^ LoadCompleted;
public event System.ComponentModel.AsyncCompletedEventHandler LoadCompleted;
member this.LoadCompleted : System.ComponentModel.AsyncCompletedEventHandler 
Public Custom Event LoadCompleted As AsyncCompletedEventHandler 

事件类型

AsyncCompletedEventHandler

示例

下面的代码示例演示如何使用此成员。The following code example demonstrates the use of this member. 在此示例中,事件处理程序报告事件的发生 LoadCompletedIn the example, an event handler reports on the occurrence of the LoadCompleted event. 此报表可帮助你了解何时发生事件,并可帮助你进行调试。This report helps you to learn when the event occurs and can assist you in debugging. 若要报告多个事件或频繁发生的事件,请考虑 MessageBox.Show Console.WriteLine 将消息替换为多行或将其追加到多行 TextBoxTo 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.

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

private void PictureBox1_LoadCompleted(Object sender, AsyncCompletedEventArgs e) {

System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
messageBoxCS.AppendFormat("{0} = {1}", "Cancelled", e.Cancelled );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Error", e.Error );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "UserState", e.UserState );
messageBoxCS.AppendLine();
MessageBox.Show(messageBoxCS.ToString(), "LoadCompleted Event" );
}
Private Sub PictureBox1_LoadCompleted(sender as Object, e as AsyncCompletedEventArgs) _ 
     Handles PictureBox1.LoadCompleted

    Dim messageBoxVB as New System.Text.StringBuilder()
    messageBoxVB.AppendFormat("{0} = {1}", "Cancelled", e.Cancelled)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "Error", e.Error)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "UserState", e.UserState)
    messageBoxVB.AppendLine()
    MessageBox.Show(messageBoxVB.ToString(),"LoadCompleted Event")

End Sub

注解

LoadCompleted仅当使用其中一种方法异步加载图像时才会发生 LoadAsync ,并且 WaitOnLoadfalseThe LoadCompleted occurs only when the image is loaded asynchronously by using one of the LoadAsync methods, and WaitOnLoad is false. 如果通过调用方法取消图像加载,则 CancelAsync Cancelled 的属性 AsyncCompletedEventArgs 将设置为 trueIf the image-load is canceled by calling the CancelAsync method the Cancelled property of the AsyncCompletedEventArgs will be set to true. 如果在加载过程中发生异常或错误,将捕获该异常或错误,并且 Error 的属性 AsyncCompletedEventArgs 将包含异常信息。If an exception or error occurs during the load process, it will be caught and the Error property of the AsyncCompletedEventArgs will contain the exception information.

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

适用于