0

I have no problem with my code as I can see, it's a breakout game, but for testing purposes I need to be able to go up,down, left, right manually with the keys http://pastebin.com/fJWk1ifH

txtBox.KeyDown += new System.Windows.Forms.KeyEventHandler(txtBox_KeyDown); //initialisation for key presson on textbox

private void txtBox_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Up)
    {
        xChange = 0;
        yChange = -(trackbarSpeed.Value);
    }

    if (e.KeyCode == Keys.Down)
    {
        xChange = 0;
        yChange = (trackbarSpeed.Value);
    }

    if (e.KeyCode == Keys.Left)
    {
        yChange = 0;
        xChange = -(trackbarSpeed.Value);
    }

    if (e.KeyCode == Keys.Right)
    {
        yChange = 0;
        xChange = (trackbarSpeed.Value);
    }
}
Mo Patel
  • 2,321
  • 4
  • 22
  • 37
Luke Waugh
  • 11
  • 3

1 Answers1

1

You could set the Form's "KeyPreview" property to true, or override the ProcessCmdKey() method as proposed here Key Events: ProcessCmdKey

The latter is the better way.

Community
  • 1
  • 1
Francis Ducharme
  • 4,848
  • 6
  • 43
  • 81