Results 1 to 9 of 9

Thread: [2005] Loading Img intor a picturebox form a FileListBox?

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2005
    Location
    Philadelphia
    Posts
    48

    [2005] Loading Img intor a picturebox form a FileListBox?

    I thought it was simple but untill i sat there not getting it right thats when it turned from simple to impossible. this is the code i am using


    VB Code:
    1. PictureBox1.ImageLocation = FileListBox1.SelectedItem

  2. #2
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    Re: [2005] Loading Img intor a picturebox form a FileListBox?

    What is the selectedItem of the listbox? Is it the location of the file? If it is you want:
    VB Code:
    1. PictureBox1.Image = Image.FromFile(FileListBox1.SelectedItem.ToString)

    If not what is the item.
    Visual Studio Team Edition 2005
    GDI+ Links: Bob Powell VB.Net Heaven
    API Links: All API Pinvoke.Net
    VB6 to VB.Net: Visual Basic 6 to .NET Function Equivalents (Thread)

  3. #3
    Addicted Member dim_kevin_as_human's Avatar
    Join Date
    Oct 2005
    Location
    Wisconsin
    Posts
    183

    Re: [2005] Loading Img intor a picturebox form a FileListBox?

    oops
    Dreaming men are haunted men.

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,446

    Re: [2005] Loading Img intor a picturebox form a FileListBox?

    Quote Originally Posted by mpdeglau
    What is the selectedItem of the listbox? Is it the location of the file? If it is you want:
    VB Code:
    1. PictureBox1.Image = Image.FromFile(FileListBox1.SelectedItem.ToString)

    If not what is the item.
    The .NET 2.0 PictureBox has new members, including ImageLocation and Load.

    What value is SelectedItem returning? Is it returning just the file name or the full path? If it's just the file name then that's your issue. You have to specify the full path to the file, otherwise how is it supposed to know what folder to look in for the specified file?

    Also, you really should be passing a String object to ImageLocation. If the ListBox contains String objects then cast:
    VB Code:
    1. PictureBox1.ImageLocation = CStr(FileListBox1.SelectedItem)
    The method that will work in all cases, String or otherwise, is:
    VB Code:
    1. PictureBox1.ImageLocation = FileListBox1.GetItemText(FileListBox1.SelectedItem)

  5. #5

    Thread Starter
    Member
    Join Date
    Dec 2005
    Location
    Philadelphia
    Posts
    48

    Re: [2005] Loading Img intor a picturebox form a FileListBox?

    Thanks i i knew you would have somthing to say that would help.

  6. #6

    Thread Starter
    Member
    Join Date
    Dec 2005
    Location
    Philadelphia
    Posts
    48

    Re: [2005] Loading Img intor a picturebox form a FileListBox?

    Turns out it didnt work maybe the fact that i have a DirListBox as well sorry to bother.

  7. #7
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,446

    Re: [2005] Loading Img intor a picturebox form a FileListBox?

    Like I said, you need to assign the entire path, not just the file name.

  8. #8

    Thread Starter
    Member
    Join Date
    Dec 2005
    Location
    Philadelphia
    Posts
    48

    Re: [2005] Loading Img intor a picturebox form a FileListBox?

    Sorry i am a little confused

  9. #9
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,446

    Re: [2005] Loading Img intor a picturebox form a FileListBox?

    Exactly what value does FileListBox1.SelectedItem return? If it is something like "MyFile.jpg" then you can't just assign that to the ImageLocation. It has to be the full path, like "C:\MyFolder\MyFile.jpg".

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