tags:

views:

51

answers:

1

Hi all, i have this code to show in a panel images with a pIctureBox :

private void ARR(int cNumber, string exc)
    {
       int Xpos = 8;
        int Ypos = 8;
        Image img;
            Image.GetThumbnailImageAbort myCallback = 
   new Image.GetThumbnailImageAbort(ThumbnailCallback);
        imgArray = new System.Windows.Forms.PictureBox[cNumber]; // assign number array 
        for (int i = 0; i < cNumber; i++)
        {
            imgArray[i] = new System.Windows.Forms.PictureBox(); 
            if (Xpos > 432) // six images in a line
            {
                Xpos = 8; // leave eight pixels at Left 
                Ypos = Ypos + 72;  // height of image + 8
            }     
            imgArray[i].Left = Xpos;
            imgArray[i].Top = Ypos;
            imgArray[i].Width = 64;
            imgArray[i].Height = 64;
            imgArray[i].Visible = true;         
            imgArray[i].SizeMode = PictureBoxSizeMode.StretchImage;
            img = Image.FromFile(exc);
            imgArray[i].Tag = exc[i]; 
            imgArray[i].Image = img.GetThumbnailImage(64, 64, myCallback, IntPtr.Zero);
            panel1.Controls.Add(imgArray[i]);
            Xpos = Xpos + 72;
        }

    }

private List GetPicture4(string Folder) {

        DirectoryInfo dir = new DirectoryInfo(Folder);
        List<string> str = new List<string>();
        FileInfo[] files = dir.GetFiles("*.jpg", SearchOption.AllDirectories);   
        NumOfFiles = files.Length;
        imgExtension = new string[NumOfFiles];

        for (int i = 0; i < NumOfFiles; i++)
        {

        foreach (FileInfo file in files)
        {
            ARR(NumOfFiles, file.FullName);
            str.Add(file.FullName);

      }
        return str;
    }

In The folder"Music" there are 30 file.jpg but when i debug the Panel show 30 picture but the same file "jpg". I don't understand where is the error :(. Do you have any advice or idea where i wrong? Thansk a lot.

Nice regards

+1  A: 

Haven't figured it out but your code won't work:

private List<string> GetPicture4(string Folder)  //you need to define the type of list you are returning
{
    DirectoryInfo dir = new DirectoryInfo(Folder);
    List<string> str = new List<string>();
    FileInfo[] files = dir.GetFiles("*.jpg", SearchOption.AllDirectories);   
    int NumOfFiles = files.Length; //here you are missing a type, int in this case
    imgExtension = new string[NumOfFiles];

    for (int i = 0; i < NumOfFiles; i++)
    {
        ARR(i, files[i].FullName); //pass i instead of NumOfFiles else in ARR the creating of the picturebox gets the same ID everytime
        str.Add(files[i].FullName);
    }

    return str;
}

EDIT: What about the ADD function:

imgArray = new System.Windows.Forms.PictureBox[cNumber]; // assign number array

This line shouldn't be here. You already creating one in the loop

PoweRoy
Thank's PowerRoy ,your help is right ,sorry for my banality but i'm a novice...however i wish you happy day.:))
JayJay
offtopic: good day to you too ;)But the error was 30 times the same image. As far as i know i didn't fix it :P
PoweRoy
I can show now 30 different images but if i download about 100 images it is so slow,however i'll work out it as soon as possible.Thanks PowerRoy
JayJay