Click here to Skip to main content
15,891,908 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm making a Windows form which allows people to select a film from different genres. Now i've used list boxs to display the list of films and genres. When a user selects a genre, the films from that genre are displayed in another list box. Now what I want is for a picture to be displayed in a picture box when the user selects a film from the listbox. I've done this for displaying film information, but im not sure how to do this for pictures.
Posted

Handle the ListBox's SelectedIndexChanged event and update the PictureBox according to the new selection.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 15-Feb-11 17:18pm    
That's good, my 5, but I already gave more detailed answer before (see the reference in my new Answer on this page).
--SA
Nish Nishant 15-Feb-11 17:20pm    
Yeah but that's for WPF. The OP's using Winforms I believe. Similar concepts though. With WPF I would recommend MVVM/binding approach with minimal code-behind.
programmer1234 15-Feb-11 17:52pm    
How do I do that?
Nish Nishant 16-Feb-11 8:28am    
See http://msdn.microsoft.com/en-us/library/system.windows.forms.listbox.selectedindexchanged.aspx
Espen Harlinn 16-Feb-11 15:14pm    
Nice and simple, my 5
I've already answered the similar question in a very detailed manner, please see my code:

Displaying an image from a list box[^].

The answer is about WPF, but System.Windows.Forms implementation is nearly identical.

—SAKryukov
 
Share this answer
 
v2
I want to show sample of my application

First I create one comboBox(comboBox1)and pictureBox(pictureBox1)
In comboBox1 have following 4 items
Blue hills
Sunset
Water lilies
Winter
And then write following code in comboBox1_SelectedIndexChanged event
C#
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
      {
          string filepath = @"C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\" + comboBox1.SelectedItem.ToString().Trim() + ".jpg";
          if(File.Exists(filepath)){
          pictureBox1.ImageLocation = filepath;
          pictureBox1.Load(filepath);
          pictureBox1.Update();
          pictureBox1.Refresh();
          pictureBox1.Visible = true;
          }
      }

When started i make pictureBox1's visible is false.

Maybe helpful

Theingi Win
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900