I am attempting to move a PictureBox(picUser) up and down via the key press events. I am newer to C# and am able to do this via VB. As such I am confused as to what the problem is with the following code:
private void picUser_keyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyCode == Keys.W)
{
picUser.Top -= 10;
}
}
There is no “error” with the code, the picturebox just doesn’t move.
A
PictureBoxhas noKeyDownevent. It has aPreviewKeyDowninstead and requires thePictureBoxto have the focus.I would suggest to use the
KeyDownof theformthat host thePictureBoxinstead and use the same exact code: