|
-
Jul 3rd, 2007, 11:20 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] [02/03] Can't move pic file used by PictureBox
I have a representation of some files. If you click on one that is a picture, a PictureBox gives you a preview of that picture. You can also delete these files. I am implementing a Recycle Bin of sorts, but when I try to Move the file in question, I get an error that states that the file is in use by another process. This only occurs when deleting pics. I can delete other files just fine. I tried to get around this by cloning the image, but that doesn't seem to work. Here is the code I am using.
Dim img as Image
img = Image.FromFile("C:\asdf.bmp")
Me.PictureBox.Image = img.Clone
And I use this to Move the file
File.Move("C:\asdf.bmp", "C:\RecycleBin\asdf0.bmp")
This happens with all pics. Nothing else is using the file, only that PictureBox.
Any ideas?
VB.Net 2008
.Net Framework 2.0
"Must you breathe? 'Cause I need heaven..."
-
Jul 3rd, 2007, 11:49 AM
#2
Re: [02/03] Can't move pic file used by PictureBox
Try disposing of your img object ie
Code:
Dim img as Image
img = Image.FromFile("C:\asdf.bmp")
Me.PictureBox.Image = img.Clone
img.Dispose()
-
Jul 3rd, 2007, 12:15 PM
#3
Thread Starter
Fanatic Member
Re: [02/03] Can't move pic file used by PictureBox
Sorry, that didn't seem to do it.
It is strange. It is telling me that the new file name (asdf0.bmp) is currently in being used by another process. However, that file doesn't exist. Now, if I Copy the file first and then try to Delete the old one, I get an error message saying the old one (asdf.bmp) is in use, which makes sense.
Also, the PictureBox gets cleared each time a new node is selected. So, if the new node isn't a pic, you see nothing.
If I have a "folder" with three files, where 2 are pics and 1 is a doc, I never have any problems deleting the doc. But, if I have ever clicked on a pic, I can't delete it. If I click on pic1, then the doc, then "Delete All In Folder", I can't delete pic1. If I click on pic1, then pic2, then the doc, then "Delete All In Folder", I can't delete either pic1 or pic2.
It seems that my use of the file in the PicBox is locking that file up.
VB.Net 2008
.Net Framework 2.0
"Must you breathe? 'Cause I need heaven..."
-
Jul 3rd, 2007, 01:22 PM
#4
Re: [02/03] Can't move pic file used by PictureBox
I ran this code using a binary reader and Image.FromStream and it seems to work. To prevent form overwrite errors when moving the tile, I do a copy and then delete.
Code:
Dim img As Image
Dim br As New IO.BinaryReader(IO.File.Open("C:\temp.jpg", IO.FileMode.Open), System.Text.Encoding.Default)
img = Image.FromStream(br.BaseStream)
br.Close()
br = Nothing
Me.PictureBox1.Image = img
IO.File.Copy("C:\temp.jpg", "C:\RecycleBin\temp0.jpg", True)
IO.File.Delete("C:\temp.jpg")
Last edited by bmahler; Jul 3rd, 2007 at 01:25 PM.
-
Jul 3rd, 2007, 01:59 PM
#5
Thread Starter
Fanatic Member
Re: [02/03] Can't move pic file used by PictureBox
That'll do. Thank you so much.
VB.Net 2008
.Net Framework 2.0
"Must you breathe? 'Cause I need heaven..."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|