|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Can't delete an image that is in a picture boxI 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 Show quoteHide quote "Tom Scales" <tjsca***@gmail.com> schreef in bericht news:xIf2g.7787$5b2.6821@tornado.tampabay.rr.com... >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 > 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 Show quoteHide quote "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message news:%236njwpeZGHA.5004@TK2MSFTNGP02.phx.gbl... > 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 > > "Tom Scales" <tjsca***@gmail.com> schreef in bericht > news:xIf2g.7787$5b2.6821@tornado.tampabay.rr.com... >>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 Scales" <tjsca***@gmail.com> schrieb: Check out the code snippets at > 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. <URL:http://dotnet.mvps.org/dotnet/code/graphics/#ImageNoLock>. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> 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 Show quoteHide quote "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message news:%23$oEjufZGHA.3848@TK2MSFTNGP05.phx.gbl... > "Tom Scales" <tjsca***@gmail.com> schrieb: >> 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. > > Check out the code snippets at > <URL:http://dotnet.mvps.org/dotnet/code/graphics/#ImageNoLock>. > > -- > M S Herfried K. Wagner > M V P <URL:http://dotnet.mvps.org/> > V B <URL:http://classicvb.org/petition/> 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 Show quoteHide quote "Tom Scales" <tjsca***@gmail.com> wrote in message news:%Hq2g.4515$Dv6.948@tornado.tampabay.rr.com... > 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 > "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message > news:%23$oEjufZGHA.3848@TK2MSFTNGP05.phx.gbl... >> "Tom Scales" <tjsca***@gmail.com> schrieb: >>> 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. >> >> Check out the code snippets at >> <URL:http://dotnet.mvps.org/dotnet/code/graphics/#ImageNoLock>. >> >> -- >> M S Herfried K. Wagner >> M V P <URL:http://dotnet.mvps.org/> >> V B <URL:http://classicvb.org/petition/> > > |
|||||||||||||||||||||||