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 = null;

Hope this helps someone out there! :)

Back to extensions list

Until next time: Work to Live, Don’t Live to Work

No comments:

Post a Comment