0
foreach (PictureBox picture in panel1.Controls)
{                    
    if (count == 12)
    {
        break;
    }
    count = count + 1;
    picture.Enabled = false;//disable clicking card
    points.Add(picture.Location);//card location in the panel
                    
}

There are 24 picture boxes, I only want to allocate the position of the first 12 picture boxes. Is there any ways can be used like for loop?

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Kyson
  • 11
  • you can get the first 12 picture boxes `panel1.Controls.Take(12).ToList()` – Reza Esmaeli Oct 31 '21 at 13:45
  • You could also just use a `for` loop and try and get the control from the `Controls` collection and then you don't need do to any `count` checks or changes: https://www.w3schools.com/cs/cs_for_loop.php – ConnorTJ Nov 01 '21 at 10:23

1 Answers1

-1

You can get the first 12 picture boxes with a for loop:

for (int i = 0; i < 12; i++)
{
    PictureBox pb = (PictureBox)panel1.Controls[i];
    // Do what you want with your picture box
}
Dalk
  • 7
  • 1