PictureBox.LoadAsync Method

Definition

Loads the image asynchronously.

Overloads

LoadAsync(String)

Loads the image at the specified location, asynchronously.

LoadAsync()

Loads the image asynchronously.

LoadAsync(String)

Loads the image at the specified location, asynchronously.

public:
 void LoadAsync(System::String ^ url);
public void LoadAsync (string url);
member this.LoadAsync : string -> unit
Public Sub LoadAsync (url As String)

Parameters

url
String

The path for the image to display in the PictureBox.

Examples

The following code example demonstrates how to use the LoadAsync method. To run this example, paste the following code into a Windows Form that contains a PictureBox named pictureBox1 and a Button named startLoadButton. Make sure that the Click event for the button is associated with the startLoadButton_Click 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

Remarks

If the url parameter indicates a local file, the recommended format is a local file path. For example, an image file named myPicture.jpglocated atc:\ would be accessed by passing c:\myPicture.jpg for the url parameter. A full path, such as http://www.contoso.com/path/images/image.jpg, or a relative path, such as ./images/image.jpg, can be used. If a relative path is used, it will be considered relative to the working directory. A call to the Load method sets the ImageLocation property to the value of url.

A call to the LoadAsync method sets the ImageLocation property to the value of url. Besides calling the LoadAsync method, you must set the WaitOnLoad property to false to load an image asynchronously. When you load an image asynchronously, you can handle the LoadProgressChanged event to determine the progress of an image load or the LoadCompleted event to determine when an image load has completed. If an error occurs during an asynchronous image-loading operation, it will be caught and reported by the Error property of the AsyncCompletedEventArgs.

LoadAsync()

Loads the image asynchronously.

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

Remarks

Besides calling the LoadAsync method, the WaitOnLoad property must be set to false to load an image asynchronously. When you load an image asynchronously, you can handle the LoadProgressChanged event to determine the progress of an image load or the LoadCompleted event to determine when an image load has completed.

Applies to