I want to select the pictures (They are select during program is running) and show them on the form. for that i take a panel on the form and populate the panel with pictureboxes.i write the following code for that but it is very time consuming:

if(openDialoge1.ShowDialog() == DialogResult.OK)
                       string[] fileName = open.FileNames;
                       foreach (string s in fileName)
                            pBox = new PictureBox();
                            pBox.Size = new System.Drawing.Size(w, h);
                            pBox.Location = new System.Drawing.Point(x, y);
                            pBox.Image = Image.FromFile(s);
                           // .
                            //.//here i add some eventHandler of picture boxes.

                            x += pBox.Width + 4;

This code work well, but it is very time consuming and take much time to populate the panel with picture boxes. for example when i slect the 20,30 pictures, it take much time.
Is there any way that reduce the time to populate the panel with pictureboxes.

Thanks in advance.

7 Years
Discussion Span
Last Post by qauaan

I think Image.FromFile() will affect the performance. Load the images into a List<> first, using a separate thread or background worker.


I have no idea that how can i use the seperate thread. can u explain with coding

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.