Getting controls relative to their position

Iamazn

New member
Joined
Oct 14, 2012
Messages
1
Programming Experience
1-3
My form has around 250 pictureboxes. I want to be able to add all of these pictureboxes into an array so that I can modify them. I am trying to shift the image from one picturebox onto the one directly on top of it. The problem is that the pictureboxes are not named in order (done on purpose). Is there any way I can grab all of the pictureboxes on my form in a right-left sort of manner?
Basically something like this:
My Form (each number represents a picturebox)
958
143
267
When using a for loop from 1-9, the array generated is something like:
123456789
When using a foreach loop, the array generated in random, in no particular order.
Is it possible to grab these pictureboxes and sort them like:
958143267
(Right->Left)



ri

 
As this question has been answered elsewhere, I thought I'd post the solution to spare anyone else wasting their time.
var rightToLeftPictureBoxes = this.Controls.OfType<PictureBox>().OrderByDescending(pb => pb.Left).ThenBy(pb => pb.Top).ToArray();
 
Back
Top Bottom