How do I generate labels dynamically in my for each?

1

What I would like to do is a list of all my uploaded images, which are in a folder of my application, this folder already contains images and I would like to put them in a list of labels, until now my code is as follows:

Code Listing Images:

DirectoryInfo d = new DirectoryInfo(@"C:\Users\NQ054\Videos\Presupuesto_Da\Imagenes\Febrero");
FileInfo[] Files = d.GetFiles("*.jpeg");
string str = "";
List<Label> labels = new List<Label>();
foreach (FileInfo file in Files)
{
    str = str + ", " + file.Name;
    Label label = new Label();
    label.Text=file.ToString();
    labels.Add(label);

}

If I debug it if you save an image by index in the list, but as I do so that the labels can be seen in my application, if there are 10 images they would be 10 labels.

  

Update

I only added the first tags, but what I want is that I add the 10 that I need for each image, those are in the list.

Code to add a tag:

this.Controls.Add(labelI);
    
asked by David 20.02.2017 в 20:02
source

1 answer

2
    foreach (FileInfo file in Files)
    {
        str = str + ", " + file.Name;
        Label label = new Label();
        label.Text=file.ToString();
        this.Controls.Add(label); <<<-----
    }

Remember also that you have to define a location and size those components (although I guess the Labels will acquire the same size of the image).

    
answered by 20.02.2017 / 20:09
source