473,386 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Picturebox

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
6 1781
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
"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
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
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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: SamSpade | last post by:
I have a usercontrol that contains a picturebox. The user can obtain (creategraphics) a picturebox graphics object and draw on the picturebox. She could do gr.GraphincInit.Millimeter and then draw...
0
by: akh | last post by:
I want to use de Drag and Drop ´s event to move a picture box from a form and within a Picture Box. But I have behaviour if the MyPBox As PictureBox as the Globale varible or not Thanks for...
3
by: Tom | last post by:
I have a picturebox on my VB.NET form. The picturebox size mode is set to stretched. I then load an image into that form and display it. As the user moves the mouse over the form, I want to get and...
2
by: Mattbooty | last post by:
Hello, Not sure if anyone else has seen this bug, but I have a form where the entire form is covered with a picturebox. The picturebox has a mouseup event. I also have an open file dialog for...
4
by: Jerry West | last post by:
I have a routine that updates a PictureBox image every x seconds. I do this by first loading an array with the path to all of the images. I then generate a random number to use as the index of the...
4
by: munibe | last post by:
Hi, i have a problem about picturebox control. if you may help me, i will be so happy. i have a picturebox named pic_map, and i added a button named customer_button, my wish is to add a new small...
3
by: kirk | last post by:
I have a form with a PictureBox control on it. The .Image property is set to a PNG file(which shows the picture of the US map) with some transparency in it. The .BackColor property is set to...
4
by: Jim McGivney | last post by:
In C# on Form1 I genetate an array of PictureBoxes and populate each with an image as seen in the code below. Later on I want to access a specific PictureBox to change its image, but I keep...
5
by: AWW | last post by:
XP VB 2005 running an example from help that creates a picturebox in code - the picturebox is not created. If I comment out the "Dim Box as New PictureBox" and create it in Design mode - the...
1
by: leshka82 | last post by:
I have recently designed a Winform Image drag & drop utility. The approach I took was to have a Panel control serve as a destination for multiple file drop. Once the user dragged & dropped the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.