PictureBox.CancelAsync 方法

定義

取消非同步影像載入。

public:
 void CancelAsync();
public void CancelAsync ();
member this.CancelAsync : unit -> unit
Public Sub CancelAsync ()

範例

下列程式碼範例會示範如何使用 CancelAsync 方法。 若要執行此範例,請將下列程式碼貼到 Windows Form 中,其中包含名為 startLoadButtoncancelLoadButton 和 的兩 ButtonpictureBox1PictureBox 控制項。 請確定 Click 按鈕的事件與此範例中的事件處理方法相關聯。 您必須將影像檔路徑變更為系統上有效的路徑。

private void startButton_Click(object sender, EventArgs e)
{
    // Ensure WaitOnLoad is false.
    pictureBox1.WaitOnLoad = false;

    // Load the image asynchronously.
    pictureBox1.LoadAsync(@"http://localhost/print.gif");
}
Private Sub startLoadButton_Click(ByVal sender As Object, _
    ByVal e As EventArgs) Handles startLoadButton.Click

    ' Ensure WaitOnLoad is false.
    pictureBox1.WaitOnLoad = False

    ' Load the image asynchronously.
    pictureBox1.LoadAsync("http://localhost/print.gif")

End Sub
private void cancelButton_Click(object sender, EventArgs e)
{
    pictureBox1.CancelAsync();
}
Private Sub cancelLoadButton_Click(ByVal sender As Object, _
    ByVal e As EventArgs) Handles cancelLoadButton.Click
    pictureBox1.CancelAsync()

End Sub

備註

PictureBox當 屬性為 false ,並使用 LoadAsync 方法載入影像時 WaitOnLoad ,會以非同步方式載入影像。 如果使用 方法取消來 CancelAsync 取消載入,則會藉由引發 LoadCompleted 事件,並將 Cancelled 的 屬性 AsyncCompletedEventArgs 設定為 true 來報告。

適用於