Click here to Skip to main content
16,022,924 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
//--form is having one flowLayoutPanel1 one fileopen dialog box and 1 button
C#
private void Form1_Load(object sender, EventArgs e)
{
    InitializeOpenFileDialog();
}
private void InitializeOpenFileDialog()
{
    // Set the file dialog to filter for graphics files.
    this.openFileDialog1.Filter =
        "Images (*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|" +
        "All files (*.*)|*.*";
    // Allow the user to select multiple images.
    this.openFileDialog1.Multiselect = true;
    this.openFileDialog1.Title = "My Image Browser";
}
private void selectFilesButton_Click(object sender, EventArgs e)
{
    DialogResult dr = this.openFileDialog1.ShowDialog();
    if (dr == System.Windows.Forms.DialogResult.OK)
    {
        // Read the files
        foreach (String file in openFileDialog1.FileNames) 
        {
            // Create a PictureBox.
            try
            {
                PictureBox pb = new PictureBox();
                Image loadedImage = Image.FromFile(file);
                pb.Height = loadedImage.Height;
                pb.Width = loadedImage.Width;
                pb.Image = loadedImage;
                flowLayoutPanel1.Controls.Add(pb);
            }
           
            catch (Exception ex)
            {
                // Could not load the image - probably related to Windows file system permissions.
                MessageBox.Show("Cannot display the image: " + file.Substring(file.LastIndexOf('\\'))
                    + ". You may not have permission to read the file, or " +
                    "it may be corrupt.\n\nReported error: " + ex.Message);
            }
        }
    }
Posted
Updated 19-Nov-11 20:13pm
v2
Comments
Mehdi Gholam 20-Nov-11 2:13am    
EDIT -> fixed formatting
Sergey Alexandrovich Kryukov 20-Nov-11 20:34pm    
WinForms? Tag it!
--SA

1 solution

If you want scroll in your flowLayoutPanel then use the property AutoScroll=True
Set AutoScroll
In some programs, the FlowLayoutPanel may end up being too small to show all the controls. In this case, you can set the AutoScroll property to True. This will make the FlowLayoutPanel display scrollbars when the controls overflow the enclosing area.
For your information
FlowLayoutPanel Class[^]
FlowLayoutPanel Examples[^]
FlowLayoutPanel[^]
 
Share this answer
 
Comments
akit_kmr 20-Nov-11 11:24am    
tried it but not worked....
Sergey Alexandrovich Kryukov 20-Nov-11 20:35pm    
Then you screw up something :-)
--SA
Sergey Alexandrovich Kryukov 20-Nov-11 20:35pm    
Right, a 5.
--SA

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