How to use loop for?

Asked

Viewed 129 times

-2

How to use loop is that it? I’ve tried every way ever wrong.

I’ll express myself better !

What I’m not getting is that this repetition of Metrotiles 1 2 3 4 5 is just one in loope for i , so it would just be metrotile[i] . something and would not have to do 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 tried that one too

for (int i = 0; i < 10; i++)
{
    MetroTile a = new MetroTile();
    metroTile.UseCustomBackColor = true(a);
}
  • what I need in this Metrotile is to add the number that I’m getting in loop Metrotile 1 Metrotile 2 from always error

  • And the guy MetroTile is everlasting?

  • is the metro interface, understood, but where they come from ?

  • the same thing happens the programs asks to create an internal Metrotile aclasse

  • @Carloscoelho Metrotile would not be a class?

  • it’s hard to help

  • Asked 21 minutes ago already with -7 votes. We have a record here!

  • 1

    I’m not voting negative and I’m trying to help you. What is metroTile1, metroTile2, metroTile3, etc? Where and how do you declare these variables?

  • He wants to use the same method for all objects of type "Metrotitle". Without having to move one by one, it is clear.

  • @Carloscoelho I believe that Marcio Cristian’s answer will help you, check and mark as "accepted" if you solve your problem.

Show 5 more comments

1 answer

3


If you are creating at runtime, the code would have to be 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 created by the designer, you’ll have to pick up the list of Tiles in some way, example:

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

Then you’d go through the list again later

  • 1

    was the way it was created by the time of execution and I thank you for your reply

Browser other questions tagged

You are not signed in. Login or sign up in order to post.