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
0 Sergey Alexandrovich Kryukov 505
1 OriginalGriff 258
2 ChintanShukla 195
3 Bhavik_Patel 170
4 Richard Deeming 165
0 Sergey Alexandrovich Kryukov 8,688
1 OriginalGriff 7,237
2 CPallini 2,598
3 Richard MacCutchan 2,080
4 Abhinav S 1,888


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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100