PictureBox.LoadProgressChanged 事件

定义

在异步图像加载操作的进度更改时发生。Occurs when the progress of an asynchronous image-loading operation has changed.

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

事件类型

ProgressChangedEventHandler

示例

下面的代码示例演示如何处理 LoadProgressChanged 事件。The following code example demonstrates how to handle the LoadProgressChanged event. 若要运行此示例,请将以下代码粘贴到一个 Windows 窗体中,其中包含名为的、一个名为的 PictureBox pictureBox1 和一个名为 Button startLoadButtonProgressBar progressBar1To 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. 请确保 startLoadButton_Click 方法与 Click 按钮的事件关联,并且 pictureBox1_LoadProgressChanged 方法与的 LoadProgressChanged 事件关联 pictureBox1Make 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 

注解

LoadProgressChanged仅当使用其中一种方法异步加载图像时才会发生 LoadAsyncThe LoadProgressChanged occurs only when the image is loaded asynchronously by using one of the LoadAsync methods. 将用的属性报告映像加载的进度百分比 ProgressPercentage ProgressChangedEventArgsThe progress percentage of the image load is reported with the ProgressPercentage property of the ProgressChangedEventArgs.

LoadProgressChanged如果要在或类似的控件中反映异步图像加载操作的进度,请处理 ProgressBarHandle the LoadProgressChanged if you want to reflect the progress of an asynchronous image-loading operation in a ProgressBar or similar control. 使用 ProgressPercentage 的属性 ProgressChangedEventArgs 来更新进度值。Use the ProgressPercentage property of the ProgressChangedEventArgs to update the progress value.

有关处理事件的详细信息,请参阅 处理和引发事件For more information about handling events, see Handling and Raising Events.

适用于