By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,572 Members | 1,439 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,572 IT Pros & Developers. It's quick & easy.

Picturebox

P: n/a
Hi Guys,

Real simple question here I'm sure. I'm trying to display a JPEG in a
picture box (VB.NET 2003).

pb.Image = Image.FromFile("C:\pic.jpg")

Then, later in the program I need to delete the image file from the disk.

pb.Image = Nothing
IO.File.Delete("C:\pic.jpg")

But I can't as the file is still open/in use. If I try to delete the image
file without displaying it in the picture box first it deletes fine, so I
know it's the picture box that's still got hold of the image file somehow.

What am I missing?
Cheers,
Paul.
Apr 1 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Hi,

Dim fs As New System.IO.FileStream("C:\bliss.jpg", IO.FileMode.Open)

Dim bm As New Bitmap(fs)

PictureBox1.Image = DirectCast(bm.Clone, Image)

fs.Close()

bm.Dispose()

System.IO.File.Delete("C:\bliss.jpg")

Ken

------------------

"Paul Hadfield" <pa**@nospamthankyoumam.com> wrote in message
news:OT**************@TK2MSFTNGP12.phx.gbl...
Hi Guys,

Real simple question here I'm sure. I'm trying to display a JPEG in a
picture box (VB.NET 2003).

pb.Image = Image.FromFile("C:\pic.jpg")

Then, later in the program I need to delete the image file from the disk.

pb.Image = Nothing
IO.File.Delete("C:\pic.jpg")

But I can't as the file is still open/in use. If I try to delete the image
file without displaying it in the picture box first it deletes fine, so I
know it's the picture box that's still got hold of the image file somehow.

What am I missing?
Cheers,
Paul.

Apr 2 '06 #2

P: n/a
"Paul Hadfield" <pa**@nospamthankyoumam.com> schrieb:
Real simple question here I'm sure. I'm trying to display a JPEG in a
picture box (VB.NET 2003).

pb.Image = Image.FromFile("C:\pic.jpg")

Then, later in the program I need to delete the image file from the disk.

pb.Image = Nothing
IO.File.Delete("C:\pic.jpg")

But I can't as the file is still open/in use. If I try to delete the image
file without displaying it in the picture box first it deletes fine, so I
know it's the picture box that's still got hold of the image file somehow.


Check out the code listings 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/>

Apr 2 '06 #3

P: n/a
Thanks Ken - perfect.

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:ek****************@tk2msftngp13.phx.gbl...
Hi,

Dim fs As New System.IO.FileStream("C:\bliss.jpg", IO.FileMode.Open)

Dim bm As New Bitmap(fs)

PictureBox1.Image = DirectCast(bm.Clone, Image)

fs.Close()

bm.Dispose()

System.IO.File.Delete("C:\bliss.jpg")

Ken

------------------

"Paul Hadfield" <pa**@nospamthankyoumam.com> wrote in message
news:OT**************@TK2MSFTNGP12.phx.gbl...
Hi Guys,

Real simple question here I'm sure. I'm trying to display a JPEG in a
picture box (VB.NET 2003).

pb.Image = Image.FromFile("C:\pic.jpg")

Then, later in the program I need to delete the image file from the disk.

pb.Image = Nothing
IO.File.Delete("C:\pic.jpg")

But I can't as the file is still open/in use. If I try to delete the
image file without displaying it in the picture box first it deletes
fine, so I know it's the picture box that's still got hold of the image
file somehow.

What am I missing?
Cheers,
Paul.


Apr 2 '06 #4

P: n/a
Hi Herfried,

Herfried wrote :
Check out the code listings at ...


I've been meaning to ask you this for some time now... Do you have an
English version of your site ? There's so much information there that I
would like to learn, but the language barrier ... ! I did do a course
in German language many years back, but my German is too rusty to be
able to understand technicalities. ;-)

Thanks,

Cerebrus.

Apr 3 '06 #5

P: n/a
Just go to google and put in the web address then click search. A seach
page should come up with a tranlate link. It's not perfect but it does the
job.

http://translate.google.com/translat...l%3Den%26lr%3D

"Cerebrus" <zo*****@sify.com> wrote in message
news:11**********************@t31g2000cwb.googlegr oups.com...
Hi Herfried,

Herfried wrote :
Check out the code listings at ...


I've been meaning to ask you this for some time now... Do you have an
English version of your site ? There's so much information there that I
would like to learn, but the language barrier ... ! I did do a course
in German language many years back, but my German is too rusty to be
able to understand technicalities. ;-)

Thanks,

Cerebrus.

Apr 3 '06 #6

P: n/a
"Cerebrus" <zo*****@sify.com> schrieb:
Check out the code listings at ...


I've been meaning to ask you this for some time now... Do you have an
English version of your site ? There's so much information there that I
would like to learn, but the language barrier ... ! I did do a course
in German language many years back, but my German is too rusty to be
able to understand technicalities. ;-)


Sorry, but I currently do not plan an English translation. However, the
tips in the FAQ collection are available in English!

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Apr 3 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.