Why can't I move my file?

May 3 2008 1:57 PM

Hi, I'm writing this little image browser written in C# with a file rename feature. Trouble is that when I try to rename the file that's displayed I get an error with a message that the picture file is being used by a process.

So I thought that I should show you the method that displays the image in a picture box and displays some information about it inside a label.

public void SetPicture(string path)

{

currentImagePath = path;

pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;

pictureBox1.Image = new Bitmap(path);

FileInfo fi = new FileInfo(path);

label1.Text = string.Format("{0}x{1}pixels {2}", pictureBox1.Image.Width, pictureBox1.Image.Height, fi.LastWriteTime);

this.Text = path;// set window title

}

 

Is the culprit here?

Thanks, Henri


Answers (3)