0

I am initializing and array of objects, i need something like this:

Greyhound[1].StartingPosition = pictureBox1.Location;
Greyhound[2].StartingPosition = pictureBox2.Location;

and so on.. but I need to make it by a loop

for ( ......... ) { Greyhound.StartingPosition = ????????? // what should go here }

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by PierlucSS
0

I would recommend using a list of greyhound, however you can do the following (assuming you are on a form)

Regex regex = new Regex(@"pictureBox(?<num>\d+)");

                        foreach( PictureBox pic in this.Controls.OfType<PictureBox>() )
                        {
                                int pictureNumber = 0;
                                int.TryParse( regex.Match( pic.Name ).Groups[ "num" ].Value , out pictureNumber );

                                Greyhound[ pictureNumber ] = pic.Location;
                        }

This would work, however we recommended solution would be to have a list of greyhound, you then use a foreach picturebox and add an item to your greyhound list with the needed information (location and id or picturebox name perhaps)

Edited by PierlucSS: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.