I want to get the object that created in struct. Showing the codes will explain it better though.
private void Obstacle()
{
obstacle_pos_x = obstacle_random_x.Next(1000);
obstacle_pos_y = obstacle_random_y.Next(700);
picture = new PictureBox
{
Name = "pictureBox" + obstacle_numb,
Size = new Size(32, 32),
Location = new Point(obstacle_pos_x,obstacle_pos_y),
BackColor = Color.Black,
};
this.Controls.Add(picture);
}
This is the struct inside of Obstacle method. As you can see this method creates pictureboxes and I want to pull them into KeyPressEvents. Like, if I press W, all the pictureboxes that created by struct has to move -10(y axis).
else if (e.KeyCode == Keys.W)
{
y -= chrspeed;
obstacle_numb++;
Obstacle();
for (int i = 0; i <= obstacle_numb; i++)
{
}
}
Well this the event. But it just creates pictureboxes. For loop is empty, because I couldn't figure out what to do. I simply want to do something like that,
picture+obstacle_numb.Location = new Point(x,y); (I need this picture+obstacle_numb combination.)
But also know that it is imposible. foreach came up to my mind but I don't know how to use it. Maybe something like this can work if fixed.
foreach(PictureBox objects from picture) //It doesn't work too.
I'm stuck right now and waiting for your help. Thanks in advance.