Friday, November 11, 2016

PictureBox SafeReplaceImage extension


Another extension for the winforms picturebox component.
Basically it just lets you forget about the disposal of the previous image. Saved me a lot of headache.

Some source-code (C#)
public static void SafeReplaceImage(this PictureBox pbox, Image image)
{
 var tmp = pbox.Image;
 pbox.Image = image;
 if (tmp != null)
 {
  tmp.Dispose();
  tmp = null;
 }
}

Hope this helps someone out there! :)

Back to extensions list


No comments:

Post a Comment