private void Form1_KeyDown(object sender, KeyEventArgs e) { int x = pictureBox1.Location.X; int y = pictureBox1.Location.Y; if (e.KeyCode == Keys.W) y -= 5; { if (pictureBox1.Bounds.IntersectsWith(pictureBox2.Bounds) == false) { pictureBox1.Location = new Point(x, y); } if (e.KeyCode == Keys.S) y += 5; { if (pictureBox1.Bounds.IntersectsWith(pictureBox2.Bounds) == false) { pictureBox1.Location = new Point(x, y); } if (e.KeyCode == Keys.A) x -= 5; { if (pictureBox1.Bounds.IntersectsWith(pictureBox2.Bounds) == false) { pictureBox1.Location = new Point(x, y); } if (e.KeyCode == Keys.D) x += 5; { if (pictureBox1.Bounds.IntersectsWith(pictureBox2.Bounds) == false) { pictureBox1.Location = new Point(x, y); } } } } } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)