wessamzeidan Posted March 12, 2004 Posted March 12, 2004 Hi, heres my problem I'm copying an image file from a cd to the hard drive using FileInfo.CopyTo() method. I'm then displaying this image in a picturebox picBox.Image=Image.FromFile(_filename) After I close the form, I want to delete this image, but I'm getting an error telling me that I can't delete it because another process is using it. I'm using the form's closing event to delete it....Any ideas? Thanks Quote Proudly a Palestinian Microsoft ASP.NET MVP My Blog: wessamzeidan.net
Administrators PlausiblyDamp Posted March 12, 2004 Administrators Posted March 12, 2004 (edited) Make sure you call picBox.Image.Dispose before deleting the file e.g. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load System.IO.File.Copy("c:\winnt\zapotec.bmp", "c:\temp\zapotec.bmp") PictureBox1.Image = Image.FromFile("c:\temp\zapotec.bmp") End Sub Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing PictureBox1.Image.Dispose() System.IO.File.Delete("c:\temp\zapotec.bmp") End Sub Edited March 15, 2007 by PlausiblyDamp Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
wessamzeidan Posted March 12, 2004 Author Posted March 12, 2004 Thanks, but I have another question. How can I get all the handles of an already opened file thanks alot Quote Proudly a Palestinian Microsoft ASP.NET MVP My Blog: wessamzeidan.net
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.