Dynamically adding images to pictureboxes.

Hi,

I would like to assign images to the dynamically created picture boxes.

For this i would like to dispose the other images which are not currently in the area of our view.

pls provide me solutions in c#.


Comments

  • This normally shouldn't be neccessary in C# because .NET's garbage collection will take care of it for you - but if you want to get that warm and fuzzy from disposing an object yourself:

    When you are getting ready to assign the image to your picturebox - first grab the existing picture (if any) and dispose of it after making the assignment.

    [code]
    var newImage = new Bitmap(100, 100);
    var oldImage = pictureBox1.Image;
    pictureBox1.Image = newImage;
    oldImage.Dispose();
    [/code]

    it is important to not dispose of an image while it is still attached to the picture box because if the picture box control tries to redraw or use the image for anything it will crash.
    ><//~Psightoplasm`~
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion