Click here to Skip to main content
15,920,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 48 Picture box arranged in a Panel. When i click a Button i need to load pictures form path "C:/temp/". Name of this 48 picture box must be created dynamically.But nothing is displaying. my code is like this.
Dim n As Integer = 1
Dim fileType As String = "*.jpeg"
Dim fileDir As String = "C:\temp\"
Dim fileName As String
Dim PDFPicture As PictureBox
For Each fileName In System.IO.Directory.GetFiles(fileDir, fileType)
    PDFPicture = New PictureBox
    Dim pdfFile As String = "picPDF" + n.ToString
    With PDFPicture
        .Name = pdfFile
        .ImageLocation = fileName.ToString
    End With
    n += 1

Please help me to solve this problem.
Updated 17-Jan-11 6:51am

Set Parent[^] property of PDFPicture

You should also position your PictureBox'es or maybe use a FlowLayoutPanel[^]

Espen Harlinn
Share this answer
tonymappila 17-Jan-11 14:25pm    
Thank you very much Espen Harlinn for u r Answer.
By using FlowLayoutPanel i can dynamically create picture box and add pictures. Now my another problem is to get click event. My requirement is when i click on each Picture box i have to open corresponding file which have same name of that picture. Please help me.
Espen Harlinn 17-Jan-11 14:37pm    
Create a method
void clickEventHandler(object sender, EventArgs e)
PictureBox PDFPicture = sender as PictureBox;
// do you stuff

and then, during the creation of the PicktureBox'es assign it to the Click event of the PictureBox

PDFPicture.Click += clickEventHandler;

I'm *much* better at expressing myself in c# than vb
You never added the picture boxes to the Controls collection of the form. You also need to set the Location and Size properties of each picture box so they don't all end up being in the exact same place, with the exact same size. It's OK to have them all the same size, just don't put them all at the same default coordinates (0,0). You'll only see one of the boxes if you do.
Share this answer

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