Moving a winform using the arrow keys
A question that I've received today was how to move a winform using the keyboard arrow keys
Its pretty simple... you need to override the ProcessCmdKey.
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
//Returns true if the character was processed by the control;
//otherwise, false.
bool bHandled = false;
switch (keyData)
{
case Keys.Right:
this.Left += 10;
bHandled = true;
break;
case Keys.Left:
this.Left -= 10;
bHandled = true;
break;
case Keys.Up:
this.Top -= 10;
bHandled = true;
break;
case Keys.Down:
this.Top += 10;
bHandled = true;
break;
}
return bHandled;
}