PictureBox.LoadCompleted 事件

定義

發生於非同步影像載入作業完成、取消或引發例外狀況時。

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

事件類型

範例

下列程式碼範例示範如何使用這個成員。 在此範例中,事件處理常式會報告事件的發生次數 LoadCompleted 。 此報告可協助您瞭解事件發生的時間,並可協助您進行偵錯。 若要報告多個事件或經常發生的事件,請考慮將 取代 MessageBox.ShowConsole.WriteLine 或將訊息附加至多行 TextBox

若要執行範例程式碼,請將它貼入包含名為 PictureBox1 之類型 PictureBox 實例的專案。 然後,確定事件處理常式與 事件相關聯 LoadCompleted

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 一種方法以非同步方式載入映射,且 WaitOnLoadfalse 時,才會發生 。 如果藉由呼叫 方法取消影像載入, CancelAsyncCancelledAsyncCompletedEventArgs 的 屬性會設定為 true 。 如果在載入程式期間發生例外狀況或錯誤,則會攔截該例外狀況,且 ErrorAsyncCompletedEventArgs 屬性將包含例外狀況資訊。

如需處理事件的詳細資訊,請參閱 處理和引發事件

適用於