Hello everyone!

I had a quick question on how to use pictures in a VB program. What I'm trying to do is when someone selects an item in a listbox, to show the corresponding jpg file. I selected the relevant jpgs from the desktop, copied them to the clipboard and then pasted them into the resources folder by right clicking on resoruces in the solution explorer and selecting paste and now they are listed under resources.

However, when I goto run the program and select one of the listbox items, I get a FileNotFoundException. The names of the files that I use in the code match those of the jpeg files that I want to use in resources. I don't understand what I'm doing wrong.

Thanks.

Here's a copy of the relevant code....

If lstCarpets.SelectedIndex = 0 Then
            picCarpet.Image = Image.FromFile("modern_geometric.jpg")
        ElseIf lstCarpets.SelectedIndex = 1 Then
            picCarpet.Image = Image.FromFile("tufenkian.jpg")
        ElseIf lstCarpets.SelectedIndex = 2 Then
            picCarpet.Image = Image.FromFile("MosqueDomee.jpg")

You still have to tell it where the file is. It it something I have always had trouble with because your program is run in bin subdirectory and either debug subdirectory or release subdirectory and your folder isn't there it is two folders back.
What I do is copy the files into the resources and use them from there. Then you can use:
picCarpet.Image = My.Resources.modern_geometric.jpg

You still have to tell it where the file is. It it something I have always had trouble with because your program is run in bin subdirectory and either debug subdirectory or release subdirectory and your folder isn't there it is two folders back.
What I do is copy the files into the resources and use them from there. Then you can use:
picCarpet.Image = My.Resources.modern_geometric.jpg

Where is the best place to put that? When I put it just after each if elseif statement, I get a message that the picture is not a member of resources.

Thanks.

You have to copy the images into the resources. Copy your images to the clipboard. Double click on the MyProjects in the Solution Explorer. Click on the resources tab. Now right click on the background and select paste. Now all your images are resources. Now you can use your code.

I tried that and it still didn't work.

I ended up having to copy the jpg files into both the bin/debug/resources folder as well as resources...now when I click on a list item, BAM...the related pic shows up!

This question has already been answered. Start a new discussion instead.