1
Reply

Picture in PictureBox Control

ianparkins

ianparkins

Nov 20 2004 7:28 PM
2.1k
Hi all, I just have a Windows Form with a PictureBox which I named ("picVehicle"), an OpenFileDialog Control named ("ofdPicture"), and a Button named ("btnOpen") - with the following code in its click event. However, for some strange reason, when I run my program->click my open button->and choose the file I want as the picture to display, nothing appears in the picture box. No exceptions/errors are thrown when compiled or ran. Here is my code. If anyone could test this code and see if it works for them that would be great. I can't figure out what is going wrong. Any help would be greatly appreciated. Thanks, Zach (Nevermore) ___________________________Code_________________________________________ private void btnOpen_Click(object sender, System.EventArgs e) { string strImageName = ""; Stream fileStream; try { ofdPicture.Filter = "JPEG Images (*.jpg,*.jpeg)|*.jpg;*.jpeg|Gif Images (*.gif|*.gif|Bitmaps (*.bmp)|*.bmp"; ofdPicture.FilterIndex=1; if (ofdPicture.ShowDialog()==DialogResult.OK) { if((fileStream=ofdPicture.OpenFile())!=null) { strImageName=ofdPicture.FileName; fileStream.Close(); picVehicle.Image=Image.FromFile(strImageName); } } } catch(Exception ex) { Console.WriteLine(ex.ToString()); } }

Answers (1)