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

Scott LysleRank #49 · 31K reputationPosted May 3, 2008, 10:17 PM EDT
It must be in the save; the code you provided works. I checked against a hard coded save using your code along with this simple save method:
private void button2_Click(object sender, EventArgs e)
{
try
{
pictureBox1.Image.Save(@"C:\Temp\Junk.jpg");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error");
}
}
Henri de Feraudy18 reputationPosted May 3, 2008, 11:10 PM EDT
Thanks Scott,
I did think of something vaguely along those lines and looked for a Close operation, but could not find one.
It does seem strange that the only way to close is to save, but I'll use that.
Henri
Henri de Feraudy18 reputationPosted May 3, 2008, 11:12 PM EDT
And one more thing, your solution does allow me to save a backup with the original name.