Export (0) Print
Expand All

PictureBox.CancelAsync Method

Note: This method is new in the .NET Framework version 2.0.

Cancels an asynchronous image load.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public void CancelAsync ()
public void CancelAsync ()
public function CancelAsync ()

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 cancelled with the CancelAsync method cancellation is reported by raising the LoadCompleted event with the Cancelled property of the AsyncCompletedEventArgs set to true.

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 the Click event for the buttons is associated with their event-handling method in this example. You will need to change the image file path to one 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 void cancelButton_Click(object sender, EventArgs e)
        {
            pictureBox1.CancelAsync();
        }

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2015 Microsoft