I have a windows form that I need to take a arrow key press and then call a function passing it a result deppending on what arrow key was pressed. I have the code for inside the function but I just don't know how to pickup the key press in the first place.
So I think the name/inputs of the second function are wrong.
What i currently have is:
public void ShowGame(string Level)
{
FormGame frmGame = new FormGame();
frmGame.SetLevel(Level);
frmGame.ShowDialog();
}
private void textBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyCode == Keys.Up)
{
Controller.PassMove(Direction.Up);
}
if (e.KeyCode == Keys.Down)
{
Controller.PassMove(Direction.Down);
}
if (e.KeyCode == Keys.Left)
{
Controller.PassMove(Direction.Left);
}
if (e.KeyCode == Keys.Right)
{
Controller.PassMove(Direction.Left);
}
}
so that top function I have is one that opens up a new form window on top of my base main one which I have a feeling might be blocking the keypress detection.
The second function is the one i want to be called when a arrow keypress is made.
I am pretty sure my internals of the second function are correct but when I open and debug the code and put a debug stopper on the start of that function and press a key it never calls that second function.
so I was just wondering if anyone can help me with the detection of key presses and how that works I have looked at so many resources but none seem to like winforms.