End image movement by pressing enter key.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • harryjthorpe
    New Member
    • Nov 2018
    • 1

    End image movement by pressing enter key.

    Hello, I am new to C# and wanted to know how I could make it so that once the user presses the enter key, the current location of the image becomes its fixed location. I was thinking that the best way to do it would be using a while loop. Help would really be appreciated. The following is my code for moving my image:

    private void pictureBox1_Key Down(object sender, KeyEventArgs e)
    {
    int x = pictureBox1.Loc ation.X;
    int y = pictureBox1.Loc ation.Y;

    {

    if (e.KeyCode == Keys.Right) x += 50;
    else if (e.KeyCode == Keys.Left) x -= 50;
    else if (e.KeyCode == Keys.Up) y -= 50;
    else if (e.KeyCode == Keys.Down) y += 50;
    pictureBox1.Loc ation = new Point(x, y);
    }
    }
Working...