Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a windows form and a picturebox in it. I was to add image to it. This is the code:


OpenFileDialog op = new OpenFileDialog();
op.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
op.ShowDialog();

if (op.ShowDialog() == DialogResult.OK)
{
PictureBox.Image = Image.FromFile(op.FileName);
}
op.Dispose();

However there is a problem. When i click cancel its not closing, when i click second time its closing. Also When I click on the image(Image0001)and then OK the filename is becoming D:\Images\Image0001. Clicking second time its working.
Why is this happening?
Posted
Updated 23-Jan-13 4:05am
v2

Perhaps, if you only call ShowDialog the once?
C#
op.ShowDialog();

if (op.ShowDialog() == DialogResult.OK)
Calling it twice opens it twice...:laugh:
 
Share this answer
 
In your code you call's op.ShowDialog() 2 times, you should remove first call.

Regards,
Maxim.
 
Share this answer
 
Comments
missak boyajian 23-Jan-13 10:17am    
I didn't notice that :) Thnx.
delete the code -> op.ShowDialog();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900