Is there an event for an image change for a PictureBox Control?

sari k picture sari k · Sep 26, 2011 · Viewed 14.5k times · Source

How do I know when the image of the picturebox change?
Is there an event for an image change?

Answer

Christophe Geers picture Christophe Geers · Sep 26, 2011

First make sure that the images are loaded asynchronously. To do this set the PictureBox's WaitOnLoad property to false (which is the default value).

pictureBox1.WaitOnLoad = false;

Then load the image asynchronously:

pictureBox1.LoadAsync("neutrinos.gif");

Create an event handler for the PictureBox's LoadCompleted event. This event is triggered when the asynchronous image-load operation is completed, canceled, or caused an exception.

pictureBox1.LoadCompleted += PictureBox1_LoadCompleted;

private void PictureBox1_LoadCompleted(Object sender, AsyncCompletedEventArgs e) 
{       
    //...       
}

You can find more information about this event on MSDN:

http://msdn.microsoft.com/en-us/library/system.windows.forms.picturebox.loadcompleted.aspx