When the typing cursor is in a textbox I want catch the Arrow keys, do some treatment then prevent this event for being handled by the input.
In KeyPress
event we have KeyPressEventArgs
that we can put e.Handled=false;
to deal with.
But Arrows keys don't trig KeyPress
event.
I have tried with e.IsInputKey = true;
then int KeyDown
Event as MS says.
Msdn Control.PreviewKeyDown Event
But seems e.Handled=false;
doesn't work neither.
Here is my current code
private void textBox1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
if (e.KeyCode == Keys.Right || e.KeyCode == Keys.Left)
e.IsInputKey = true;
}
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Right || e.KeyCode == Keys.Left)
{
// some other treatment [...]
e.Handled = false;
}
}
I want to change the default pressing arrow behaviour in TextBox which moves the cursor. I don't want to the typing cursor between "r" and "l" (above) could be able to move.
Any suggestion?