Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I'm new to VB and I'm attempting to use several picture boxes on a panel to display multiple randomly user selected images/pictures (JPG) from file using the OpenFileDialog. The idea of the panel is to be able to scroll through multiple images/pictures side by side and in rows. Because the images/pictures need to be randomly selected from file by user I don't want to use an image list which only loads a preselected list of images/pictures. My attempts at finding a code which places a different user selected image/picture, one in each picture box (i.e. PictureBox1 = Pic1; PictureBox2=Pic2, etc.) resulted in only one image being generated in all picture boxes even though I have set the OpenFileDialog's multiselect property to true?

Any help would be greatly appreciated!

Thanks,

John.

What I have tried:

VB
Private Sub SelectFileButton_Click(sender As Object, e As EventArgs) Handles SelectFileButton.Click

        ' Show the Open File dialog. If the user clicks OK, load the
        ' picture that the user chose.

        Dim ofd As New OpenFileDialog
        If ofd.ShowDialog = DialogResult.OK Then
            If ofd.FileName <> String.Empty Then
                PictureBox1.Image = Bitmap.FromFile(ofd.FileName)
            End If
        End If

    End Sub
Posted
Updated 1-Mar-17 11:10am
v2
Comments
[no name] 1-Mar-17 17:32pm    
"I'm new to VB", then you should get familiar with reading the documentation for the controls/classes that you use. https://msdn.microsoft.com/en-us/library/system.windows.forms.filedialog.filenames(v=vs.110).aspx
Member 13032047 2-Mar-17 15:18pm    
Interestingly enough, that's what I've been doing! However, familiarity with the controls and numerous webpages, tutorials, etc. has not produced anything beyond a picture viewer that views one image at a time (which is what a pb does), a picture viewer that views multiple images by clicking on a button, loading images through ImageList control, etc. If you read beyond the "I'm new to VB" (as in, not a veteran of 30 years!) you might find that the controls are not the issue! What I'm interested in is displaying more than one random user selected image from file at a time in several pb's. The issue is to code for randomly selected images from file to be displayed, each one in its own separate picture box! I also successfully followed a tutorial for dynamically generating pb's on a panel and displaying different images in each one from ImageList, however the images are all out of focus! It's much wiser to hear a question before you try to answer it! I might remind you of the box at the bottom of the page which reads:

When answering a question please:
1. Read the question carefully.
2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome!

Let's work to help developers, not make them feel stupid.
Garth J Lancaster 1-Mar-17 19:05pm    
I'm guessing if you're using "OpenFileDialog" you're using a Winforms based project ? .. have you thought about perhaps displaying the images in a ListView or DataGridView ?
Member 13032047 2-Mar-17 15:28pm    
Hi Garth, yes I'm using OFD and Winforms. No, I did think about ListView, but kept going on the Panel/PictureBox idea because seems like what everyone talks about in tutorials/articles, etc. I hadn't thought about the DataGridView and presume that would use a DB as data source for images? The panel works well for scrolling images because it creates scrollbars automatically when image/images are larger than display area. Also, picture boxes seem to be widely used? I'll have another look at ListView! Thanks for your help!
Garth J Lancaster 2-Mar-17 17:09pm    
"and presume that would use a DB as data source for images?" .. sure, you can, but you dont have to do that - you can set the whole thing up programatically... how about 'middle ground', OFD -> DataTable or ListView, bind the DataTable to a Listview or DataGridView

Your question obviously isnt the 'boring' normal stuff - it may need you to play with a few controls/techniques till you find something that meets your requirements

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