|
-
Dec 3rd, 2009, 11:11 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] PictureBox No image available HELP
The program i am trying to build populates a series of textboxes from a csv datafile and picturebox upon text change.
The problem I ran into is that if there is no picture for a particular record the rest of the record doesnt populate into the textboxes
My thought, and perhaps someone has a better idea on how to handle this behavior is to have a default image loaded in the event, no image was present.
Not sure how to code this statement:
picture box Code:
Me.PictureBox1.Image = Image.FromFile(String.Format("{0}\{1}.jpg", Subject_Values.Label38.Text, Me.list1_MLStxt.Text))
I was going to do so something like this:
potential code Code:
If Image.FromFile(String.Format("{0}\{1}.jpg", Subject_Values.Label38.Text, Me.list1_MLStxt.Text)) Is Nothing Then
Me.PictureBox1.Image = defaultimage.jpg
If this is a good way to handel the behavior then my question is where would the default image be stored? The program would have to be compiled with the default image? I have yet to compile a program before, getting close though
Thanks for any ideas or help
-
Dec 3rd, 2009, 11:14 PM
#2
Re: PictureBox No image available HELP
What you could do is use the File.Exists() to check if the file exists before trying to load it. If it does, load it. if it doesn't, then load your default image. I would probably store the default image as a resource in my project, then access it from My.Resources.
-
Dec 3rd, 2009, 11:27 PM
#3
Re: PictureBox No image available HELP
That functionality is already built into the PictureBox control. Instead of calling Image.FromFile to create an Image object first and then assigning that to the Image property of the PictureBox, just assign the file path to the ImageLocation property of the PictureBox. If an error occurs trying to load the Image then the control's ErrorImage will be displayed instead. By default that is the same as the missing image icon in IE but you can set it to something else in the designer if you want.
-
Dec 3rd, 2009, 11:44 PM
#4
Thread Starter
Frenzied Member
Re: PictureBox No image available HELP
 Originally Posted by jmcilhinney
That functionality is already built into the PictureBox control. Instead of calling Image.FromFile to create an Image object first and then assigning that to the Image property of the PictureBox, just assign the file path to the ImageLocation property of the PictureBox. If an error occurs trying to load the Image then the control's ErrorImage will be displayed instead. By default that is the same as the missing image icon in IE but you can set it to something else in the designer if you want.
Thanks that's perfect actually
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|