Click here to Skip to main content
15,395,257 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Friends,
I am Trying to add the picturebox dynamically in my C# win. form. it is bing loded but when i am trying to get picturebox image ie. PictureBox.Image then it is giving me null value. Suppose i have 20 picturebox then starting 2-3 Picturebox.Image is not null but rest of are null...

My code

private void button2_Click(object sender, EventArgs e)
if (folderpath.ShowDialog() == DialogResult.OK)
string path = folderpath.SelectedPath;

DirectoryInfo di = new DirectoryInfo(path);

FileInfo[] Images = di.GetFiles("*.jpg");

foreach (var img in Images)
PictureBox picture = new PictureBox
Name = "pictureBox" + i,
Size = new Size(316, 320),
Location = new Point(i * 316, 1),

SizeMode = PictureBoxSizeMode.AutoSize
if (img.Name.Substring(0, 5) == "Errod")
picture.ImageLocation = img.FullName;

picture.ImageLocation = img.FullName;


please help me out for this problem

thanks in Advance.

1 solution

I Have created you a small project in C# That you can load images from a directory and display.

its a Dropbox download

If you are happy with the results please remember to accept my result.


Good Luck

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