How to use loop for? [closed]

-2

How to use loop for this? I've always tried to make mistakes.

I'll express myself better!

What I'm not getting and that this repetition of Metrotiles 1 2 3 4 5 is just one in loope for i, then it would just be metrotile [i]. something and would not have to do it repeatedly

metroTile1.UseCustomBackColor = true;
metroTile2.UseCustomBackColor = true;
metroTile3.UseCustomBackColor = true;
metroTile4.UseCustomBackColor = true;
metroTile5.UseCustomBackColor = true;
metroTile6.UseCustomBackColor = true;
metroTile7.UseCustomBackColor = true;
metroTile8.UseCustomBackColor = true;
metroTile9.UseCustomBackColor = true;
metroTile10.UseCustomBackColor = true;

I've tried it this way

MetroTile a = new MetroTile();
a[i].UseCustomBackColor = true;

I've tried this too

for (int i = 0; i < 10; i++)
{
    MetroTile a = new MetroTile();
    metroTile.UseCustomBackColor = true(a);
}
    
asked by anonymous 01.08.2017 / 15:34

1 answer

3

If you are creating at runtime, the code would have to look like this:

for(int i = 0; i < 10; i++) 
{
   var metrotile = new MetroTile();
   metrotile.UseCustomBackColor = true;

   //aqui vc adicionaria em um Control ou em uma lista qualquer
   this.Controls.Add(metrotile);
}

Now if you've already created it by the designer, you'll have to get the Tiles list somehow, for example:

var listaTiles = this.Controls.OfType<MetroFramework.Controls.MetroTile>().Select(t => t);

Then you would go through the list again later

    
01.08.2017 / 15:40