Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

C# Listbox and PictureBox problem

  • 22-12-2004 09: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, Registered Users 2 Posts: 45,085 ✭✭✭✭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