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);
}

VulpesRank #55 · 29.2K reputationPosted Sep 1, 2014, 3:44 AM EDT
if (OpenFileDialog.FileName == txtSource.Text) return;
if (pictureBox1.Image != null) pictureBox1.Image.Dispose();
Dipankar BiswasRank #992 · 2K reputationPosted Sep 1, 2014, 4:15 AM EDT
IsraelRank #1,223 · 1.5K reputationPosted Sep 1, 2014, 7:11 AM EDT
Thanx for your codes. But its still shows the blank surface in the OpenFileDialog and I cant see directories and files.
@Dipankar Biswas
This your codes:
When the OpenFileDialog it's open I can see all directories and files. But when the pictureBox receive the image without resizing himself inside in the box. I try to choose in the properties SizeMode = StrechImage. But nothing!
using (OpenFileDialog dlg = new OpenFileDialog())
{
dlg.Title = "Open Image";
dlg.Filter = "jpg files (*.jpg)|*.jpg";
if (dlg.ShowDialog() == DialogResult.OK)
{
PictureBox PictureBox1 = new PictureBox();
// Create a new Bitmap object from the picture file on disk,
// and assign that to the PictureBox.Image property
pictureBox1.Image = new Bitmap(dlg.FileName);
VulpesRank #55 · 29.2K reputationPosted Sep 1, 2014, 8:12 AM EDT
IsraelRank #1,223 · 1.5K reputationPosted Sep 1, 2014, 3:01 PM EDT
VulpesRank #55 · 29.2K reputationPosted Sep 1, 2014, 3:29 PM EDT
It sounds to me as though there's some sort of bug.
I did a search and found this thread:
http://www.vbforums.com/showthread.php?620646-RESOLVED-Openfiledialog-now-blank
The suggestion there was to re-install VS so I'd do that.
IsraelRank #1,223 · 1.5K reputationPosted Sep 2, 2014, 4:45 AM EDT
VulpesRank #55 · 29.2K reputationPosted Sep 2, 2014, 5:11 AM EDT
You said before that this didn't work but that may have been because you were creating a new PictureBox rather than using the original one.