Can't delete an image that is in a picture box

  • Thread starter Thread starter Tom Scales
  • Start date Start date
T

Tom Scales

I am having a problem with an application I am writing in vb.net 2003.

I display an image (JPG) on the screen using a Picturebox, loading it with
image.fromfile.

The user can select a key to delete the image.

If I try to delete it, it throws an error that the file is in use.

I tried the image.dispose() method, which allows me to copy the file and
MOST of the time delete the file, but not always. Sometimes it still throws
the in use error.

Any thoughts? Do I need to force garbage collection?

Thanks,

Tom
 
Tom,

The most sufficient way is for this forever to read first the image in an
image and use that image for your picture box.

If you stream it direct you have to close it and than it is gone.

Cor
 
I can live with it being gone, as I don't need it anymore, but HOW do you
close it?

By read it into an image, do you mean:

Dim tmpImage as image.fromfile("c:\image.jpg")
dim tmpBox as picturebox.image = tmpImage

I have tried every variation of this with no luck.

Tom
 
That looks perfect and seems to work. I can't imagine why the extra step is
necessary, since I am doing a dispose before the delete, but.....

Tom
 
For whatever reason, when you open and image and load it into a PictureBox,
VB leaves the file locked until the image is no longer being used. Check out
Bob Powell's GDI+ FAQ at this address: http://www.bobpowell.net/faqmain.htm
for a better explaination.
james

Tom Scales said:
That looks perfect and seems to work. I can't imagine why the extra step
is necessary, since I am doing a dispose before the delete, but.....

Tom
 
Back
Top