Επεξεργασία

Κοινή χρήση μέσω


PictureBox.LoadProgressChanged Event

Definition

Occurs when the progress of an asynchronous image-loading operation has changed.

public:
 event System::ComponentModel::ProgressChangedEventHandler ^ LoadProgressChanged;
public event System.ComponentModel.ProgressChangedEventHandler LoadProgressChanged;
public event System.ComponentModel.ProgressChangedEventHandler? LoadProgressChanged;
member this.LoadProgressChanged : System.ComponentModel.ProgressChangedEventHandler 
Public Custom Event LoadProgressChanged As ProgressChangedEventHandler 

Event Type

Examples

The following code example demonstrates how to handle the LoadProgressChanged event. To run this example, paste the following code into a Windows Form that contains a PictureBox named pictureBox1, a Button named startLoadButton, and a ProgressBar named progressBar1. Make sure that the startLoadButton_Click method is associated with the Click event for the button and the pictureBox1_LoadProgressChanged method is associated with the LoadProgressChanged event for pictureBox1. 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
void pictureBox1_LoadProgressChanged(object sender, 
    ProgressChangedEventArgs e)
{
    progressBar1.Value = e.ProgressPercentage;
}
Private Sub pictureBox1_LoadProgressChanged(ByVal sender As Object, _
    ByVal e As ProgressChangedEventArgs) _
    Handles pictureBox1.LoadProgressChanged

    progressBar1.Value = e.ProgressPercentage

End Sub

Remarks

The LoadProgressChanged occurs only when the image is loaded asynchronously by using one of the LoadAsync methods. The progress percentage of the image load is reported with the ProgressPercentage property of the ProgressChangedEventArgs.

Handle the LoadProgressChanged if you want to reflect the progress of an asynchronous image-loading operation in a ProgressBar or similar control. Use the ProgressPercentage property of the ProgressChangedEventArgs to update the progress value.

For more information about handling events, see Handling and Raising Events.

Applies to