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);
}
VulpesPosted Sep 1, 2014, 7:44 AM
if (OpenFileDialog.FileName == txtSource.Text) return;
if (pictureBox1.Image != null) pictureBox1.Image.Dispose();
VulpesPosted Sep 2, 2014, 9:11 AM
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.
IsraelPosted Sep 2, 2014, 8:45 AM
VulpesPosted Sep 1, 2014, 7:29 PM
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.
IsraelPosted Sep 1, 2014, 7:01 PM
VulpesPosted Sep 1, 2014, 12:12 PM
IsraelPosted Sep 1, 2014, 11:11 AM
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);
Dipankar BiswasPosted Sep 1, 2014, 8:15 AM