Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

C# Listbox and PictureBox problem

Options
  • 22-12-2004 9:54pm
    #1
    Closed Accounts Posts: 94 ✭✭


    Im reading in links to images(images stored on my hard drive) to a list box using open file dialog. When I click the links to the images in the list box I want the image linked to appear in a picture box. Any ideas/suggestions?

    Below is the code Ive wrote so far:

    openImage = new OpenFileDialog();
    openImage.Filter = "Jpeg (*.Jpeg | *.jpg";

    openImage.Multiselect = true;

    if(openImage.ShowDialog() == DialogResult.OK)
    {
    lstOutput.Items.Add(openImage); //lstOutput is the list box)


    Navigate.Add(Image.FromFile(openImage.FileName)); //Navigate is an Arraylist

    }


Comments

  • Registered Users Posts: 43,907 ✭✭✭✭Basq


    Way ahead of you!

    :)

    I've it in a different way.. i've all my photos linked to in a database (containing columns for photo_id, location, category etc) and the photo_id (primary key in the DB) is shown in the listBox.. then when you click the photo_id, the location is looked up in the database. The image at that location is then loaded into the ListBox.

    This should help you out somewhat... this will produce a FileOpen Box with every sort of image that can be loaded, i think! And after you click OK, will put that image into a picture box (named picSelectedPhoto). Regarding the ArrayList, can't really help you with that as i'm using the database:

    OpenFileDialog openImage = new OpenFileDialog();

    openImage.Filter = "All Image Files | *.bmp; *.gif; *.jpeg; *.jpg; *.png; *.jfif; *.tif; *.tiff; *.wmf; *.emf |" + "Windows Bitmap (*.bmp) | *.bmp|" + "Windows Icon (*.ico) | *.ico|" + "Graphics Interchange Format (*.gif) | *.gif|" + "JPEG File Interchange Format (*.jpg) | *.jpeg; *.jpg; *.jpeg, *.jfif|" + "Portable Network Graphics (*.png) | *.png|" + "Tag Image File Format (*.tif) | *.tif; *.tiff|" + "Windows Metafile (*.wmf) | *.wmf|" + "Enhanced Metafile (*.emf) | *.emf|" + "All Files (*.*) | *.*";

    if(openImage.ShowDialog() == DialogResult.OK)
    {
    try
    {
    MyImage = Image.FromFile(openImage.FileName);
    picSelectedPhoto.Image = (Image) MyImage;
    }
    catch
    {
    MessageBox.Show("Not An Image File", "Not Image");;
    }
    }

    Haven't went near my game since being off on holidays.


  • Closed Accounts Posts: 94 ✭✭weerez


    Thanks for the help Basquille but the problem I have is with the list box part. I have the same code as you but I need help on the part when you click on one of the items in the listbox and the image appears in the picture box. I appreciate the help though, cheers.


Advertisement