Export (0) Print
Expand All

PictureBox.LoadAsync Method (String)

Loads the image at the specified location, asynchronously.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public void LoadAsync(
	string url
)

Parameters

url
Type: System.String

The path for the image to display in the PictureBox.

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.

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");
}

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft