Using the code below, the left and right arrow keys function as expected, but the up and down arrows are not recognized (passing through it, the first two conditions are met where necessary, but never in the second):
private void textBox1_KeyDown(object sender, KeyEventArgs e) { TextBox tb = (TextBox)sender; if (e.KeyCode.Equals(Keys.Left)) { SetFocusOneColumnBack(tb.Name); e.Handled = true; return; } if (e.KeyCode.Equals(Keys.Right)) { SetFocusOneColumnForward(tb.Name); e.Handled = true; return; } if (e.KeyCode.Equals(Keys.Up)) { SetFocusOneRowUp(tb.Name); e.Handled = true; return; } if (e.KeyCode.Equals(Keys.Down)) { SetFocusOneRowDown(tb.Name); e.Handled = true; return; } }
Why is this and how can I fix it?
UPDATE
Here is what I see when I hover over e.Keycode when going through. If i clicked
- ... Left arrow key, I see:
e.KeyCode = "LButton | MButton | Space"
- ... Right arrow key, I see:
e.KeyCode = "LButton | RButton | MButton | Space"
- ... Up arrow, I see:
e.KeyCode = "RButton | MButton | Space"
- ... the down arrow, I see:
e.KeyCode = "Backspace | Space"
It puzzled me (what it shows me), but on keyleft and keyright my code is entered - it is never used for keyup and keydown, no matter how hard I grit my teeth.
source share