Display Error Image in PictureBox
How do you display an error image in a picturebox if no image is located to display
Quote:
Me.PictureBox1.ImageLocation = (String.Format("{0}\{1}.jpg", Subject_Values.ToolStripStatusLabel3.Text, "Subject Front"))
Me.PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
Thanks
Re: Display Error Image in PictureBox
vb.net Code:
Try
PictureBox1.Image = Image.FromFile("C:\test.txt") 'or whatever
Catch
PictureBox1.Image = PictureBox1.ErrorImage
End Try
Re: Display Error Image in PictureBox
Prevention is generally better than cure. You can first check that there is a value using String.IsNullOrEmpty and, assuming there is a value, use File.Exists to check whether there is a such a file. If either of those fail then don't even try to load the image. You should still have the Try...Catch block anyway though, in case the file the user selects is not a valid image file.
Re: Display Error Image in PictureBox
Thanks for th insight John
I am attemtipng to load/display 3 images in the new form and if 1 or 2 images is missing i still would like to be able to load the form
thats why i was interested in having the error image be displayed for an image the was missing a picture