Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
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 23-Jan-13 3:56am
Edited 23-Jan-13 4:05am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Perhaps, if you only call ShowDialog the once?
op.ShowDialog();
 
if (op.ShowDialog() == DialogResult.OK)
Calling it twice opens it twice...Laugh | :laugh:
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

In your code you call's op.ShowDialog() 2 times, you should remove first call.
 
Regards,
Maxim.
  Permalink  
Comments
missak boyajian at 23-Jan-13 10:17am
   
I didn't notice that :) Thnx.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

delete the code -> op.ShowDialog();
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 OriginalGriff 448
1 Sergey Alexandrovich Kryukov 425
2 Abhinav S 408
3 sanket saxena 285
4 Tadit Dash 160
0 Sergey Alexandrovich Kryukov 8,482
1 OriginalGriff 4,830
2 Peter Leow 3,794
3 Maciej Los 3,515
4 Er. Puneet Goel 3,107


Advertise | Privacy | Mobile
Web04 | 2.8.140415.2 | Last Updated 24 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid