Sunday, 11 August 2013

The dispose of an openFileDialog in c#?

The dispose of an openFileDialog in c#?

I have searched throughout entire stackoverflow, but couldn't find an
answer to the following:
When i'm using my openFileDialog, the files i open get blocked for use out
of my program until i close my program. So if i open an image, i am not
allowed to replace that image in my windows explorer anymore.
I think this is a problem with disposing my openFileDialog, but i'm not
sure how to solve it...
My code:
using (OpenFileDialog ofd = new OpenFileDialog())
{
ofd.Title = "Open Image";
ofd.Filter = "PNG Image(*.png|*.png" + "|GIF Image(*.gif|*.gif" +
"|Bitmap Image(*.bmp|*.bmp" + "|JPEG Compressed Image
(*.jpg|*.jpg";
if (ofd.ShowDialog() == DialogResult.OK)
{
pictureBox1.Image = new Bitmap(ofd.FileName);
}
}
I thought that the using block would solve this problem, but nope.. it
still get's used by the program. I want to load the image in the
picturebox and then i want the image to be available again (so i can
rename it, replace it etc...)

No comments:

Post a Comment