Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I know when an Image is loaded in Picturebox

Tags:

c#

.net

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?

like image 557
user Avatar asked Sep 21 '12 06:09

user


1 Answers

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.

like image 145
Larry Avatar answered Sep 24 '22 19:09

Larry