user
user

Reputation: 5411

How do I know when an Image is loaded in Picturebox

I've some huge images (7000*5000) to load simultaneously in my program, which I'm displaying in picturebox one by one. These images take some time to load in the PictureBox. At first I'm loading all the images in an Image array as Bitmap, then I'm just showing the first image in picturebox picturebox.Image = imageArray[0]. So I want to show wait cursor until first image is shown in Picturebox. Is there any way to know when the first image is shown on Picturebox?

Upvotes: 6

Views: 3784

Answers (1)

Larry
Larry

Reputation: 18031

You can use the PictureBox events : LoadProgressChanged to show the loading progress and LoadCompleted to do something when it is finished.

private void pictureBox1_LoadProgressChanged(object sender, ProgressChangedEventArgs e)
{
    // animate a progressbar...
}

private void pictureBox1_LoadCompleted(object sender, AsyncCompletedEventArgs e)
{
    // done !
}

To make this work, you have to keep the .WaitOnLoad value property to False, and you have to use one of the LoadAsync method.

Upvotes: 8

Related Questions