A PictureBoxhas no event KeyDown. Instead, he has PreviewKeyDownand requires that he has PictureBoxfocus.
I would suggest using the KeyDown formone that is hosted PictureBoxand using the exact same code:
public Form1()
{
InitializeComponent();
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyDown);
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.W)
{
picUser.Top -= 10;
}
}
Larry source
share