In order to be able to delete a file, everything that points to the file must have been disposed. Candidates are: Image.FromFile, Image.FromStream, PictureBox.ImageLocation The problem here is you have to do special things at the end of the PictureBox's life; if the image is used in more than one location in your code, it may be hard to correctly decide on its disposal. There also is a different approach, where the problem is avoided beforehand, by copying the image; this is a schematic example:
Image image1=Image.FromFile(...);
Bitmap bitmap1=new Bitmap(image1); // bitmap1 is unrelated to the file!
image1.Dispose(); // now the file is deletable
PictureBox.Image=bitmap1;
...
myForm.Close(); // will lead to PictureBox disposal
// bitmap1 will be garbage collected at some point, this does not affect the file
:)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.