Results 1 to 4 of 4

Thread: [RESOLVED] PictureBox No image available HELP

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2009
    Location
    Los Angeles
    Posts
    1,335

    Resolved [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:
    1. 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:
    1. If Image.FromFile(String.Format("{0}\{1}.jpg", Subject_Values.Label38.Text, Me.list1_MLStxt.Text)) Is Nothing Then
    2.             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

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    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.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2009
    Location
    Los Angeles
    Posts
    1,335

    Re: PictureBox No image available HELP

    Quote Originally Posted by jmcilhinney View Post
    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
  •  



Click Here to Expand Forum to Full Width