Israel

Israel

  • 701
  • 1.3k
  • 217.2k

OpenFileDialog showing a blank surface

Sep 1 2014 7:24 AM
Hi!
 
I put on my form the "openFileDialog", a "textBox", a "pictureBox" and a "Button". What I need? When I click on my button its shows all directories and files. Then I can select one foto and its put it on the "pictureBox". Until there its working well. But what I realize?
After to see everything working correctly... Without closing my current form when I realize its not the right image to put. What I do? I want to change it. Then when I click another time on my button... I see my "openFileDialog" showing me a blank surface without directories and fotos as before. Then I have to close it again completly my form to do the same process to show correctly.
Please look on my code (Its works well just that problem as I explaned):
 
private void btnOpenFile_Click(object sender, EventArgs e)
{
if (OpenFileDialog.ShowDialog() != DialogResult.Cancel)
txtSource.Text = OpenFileDialog.FileName;
else
txtSource.Text = "";
OpenFileDialog.Title = "Open Image";
OpenFileDialog.Filter = "jpg files (*.jpg)|.jpg";
//if (OpenFileDialog.ShowDialog() == DialogResult.OK)
//{
pictureBox1.Image = Image.FromFile(OpenFileDialog.FileName);
}

Answers (8)