I want my picturebox to move continuously when I press one of the arrow keys. (tap right arrow key and it stars moving right)? I am using this to make it move.
void Form1_KeyDown(object sender, KeyEventArgs e) { int x = picCharlie.Location.X; int y = picCharlie.Location.Y; if (e.KeyCode == Keys.Right) { Boolean didIHitAWall = false; foreach (Control c in this.Controls) { if (c.Name.Contains("lbl")) { Rectangle newCharlie = new Rectangle(picCharlie.Location.X + 4, picCharlie.Location.Y, picCharlie.Width, picCharlie.Height); if (newCharlie.IntersectsWith(c.Bounds)) { didIHitAWall = true; } } } if (!(didIHitAWall)) x += 4; } else if (e.KeyCode == Keys.Left) { Boolean didIHitAWall = false; foreach (Control c in this.Controls) { if (c.Name.Contains("lbl")) { Rectangle newCharlie = new Rectangle(picCharlie.Location.X - 4, picCharlie.Location.Y, picCharlie.Width, picCharlie.Height); if (newCharlie.IntersectsWith(c.Bounds)) { didIHitAWall = true; } } } if (!(didIHitAWall)) x -= 4; } else if (e.KeyCode == Keys.Up) { Boolean didIHitAWall = false; foreach (Control c in this.Controls) { if (c.Name.Contains("lbl")) { Rectangle newCharlie = new Rectangle(picCharlie.Location.X, picCharlie.Location.Y - 4, picCharlie.Width, picCharlie.Height); if (newCharlie.IntersectsWith(c.Bounds)) { didIHitAWall = true; } } } if (!(didIHitAWall)) y -= 4; } else if (e.KeyCode == Keys.Down) { Boolean didIHitAWall = false; foreach (Control c in this.Controls) { if (c.Name.Contains("lbl")) { Rectangle newCharlie = new Rectangle(picCharlie.Location.X, picCharlie.Location.Y + 4, picCharlie.Width, picCharlie.Height); if (newCharlie.IntersectsWith(c.Bounds)) { didIHitAWall = true; } } } if (!(didIHitAWall)) y += 4; }