I am trying to learn c# by making simple game. I have a picture box that I am controlling with the keyboard and another picture box. How to make the one I am controlling move over the other picture and how to chose which picture-boxes is on top of the other picture-boxes?
public Form1()
{
InitializeComponent();
}
int speed = 20;
Point xy = new Point();
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
xy = pic1.Location;
xy = Methods.MoveXY(xy, e,speed);
pic1.Location = xy;
}
public static Point MoveXY(Point xy, KeyPressEventArgs e,int speed)
{
switch (e.KeyChar)
{
case 'd':
xy.X += speed;
break;
case 'a':
xy.X -= speed;
break;
case 'w':
xy.Y -= speed;
break;
case 's':
xy.Y += speed;
break;
}
The two picture boxes are created by drag and drop in the form1 designer.