PictureBox.CancelAsync Method

Definition

Cancels an asynchronous image load.

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

Examples

The following code example demonstrates how to use the CancelAsync method. To run this example, paste the following code into a Windows Form that contains a PictureBox named pictureBox1 and two Button controls named startLoadButton and cancelLoadButton. Make sure that the Click event for the buttons is associated with their event-handling method in this example. You must change the image file path to a path that is valid on your system.

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

Remarks

A PictureBox image is loaded asynchronously when the WaitOnLoad property is false and the LoadAsync method is used to load the image. If a load is canceled with the CancelAsync method cancellation is reported by raising the LoadCompleted event with the Cancelled property of the AsyncCompletedEventArgs set to true.

Applies to