Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Proudly a Palestinian

Microsoft ASP.NET MVP

My Blog: wessamzeidan.net

  • Administrators
Posted (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 by PlausiblyDamp

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...