Object Orientation

Moderators: None (Apply to moderate this forum)
Number of threads: 44
Number of posts: 76

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Dynamically adding images to pictureboxes. Posted by meetvissuin on 5 May 2009 at 12:41 AM
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#.


Report
Re: Dynamically adding images to pictureboxes. Posted by Psightoplazm on 7 May 2009 at 2:16 PM
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.

var newImage = new Bitmap(100, 100);
var oldImage = pictureBox1.Image;
pictureBox1.Image = newImage;
oldImage.Dispose();


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`~



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.