I already had an image inside the PictureBox control, and now I want to transfer a new one to it.
What happens is that allpication Dispos (and I catch the exception: "The parameter is not valid").
This is my code:
using (Image img = Image.FromFile(open.FileName)) { part.Picture = img; pictureBox1.InitialImage = null; pictureBox1.Image = img; }
So, when the code exits the method, it becomes open to Displose this and the main form. I will catch the exception only on the line where Form1 was run. There are no exceptions to this that have ever been so. It must be something wrong while the pictureBox is being drawn (inside the Paint event), but I'm not distracted by it.
I really don't know how to solve this problem. I even tried to use to clear all resources (causing garbage collection), but nothing works.
One more thing: "part" is a link in the List, so when I try to delete the current image (to replace it with a new one), I got another exception, for example:
"The process cannot access the file because it is being used by another process."
Is this due to the 1st exception (when the new image is not painted in the pictureBox)?
c # image dispose
Mitja bonca
source share