Hi! I have a simple form windows application, on which I have put a custom control for my specific task, I have written the KeyDown Handler for Form, the problem is that the KeyDown handler is working fine with every key other than the arrows keys... The control doesn't come in to key handler? why it is so? when I remove the custom control it starts working fine?
+1
A:
Take a look at this SO question.
Is KeyPreview on? What control has focus?
Stevo3000
2009-06-26 12:10:32
yes the KeyPreview is On for Form, and My custom control has the focus, but why it is not capturing the arrow keys only? it is working fine with all other keys, one thing I have noticed that KeyUp event is fired, but not keydown....
2009-06-26 12:50:44
Did you follow the link? Does your custom control contain a text box?
Stevo3000
2009-06-26 13:21:49
A:
I don't see the reason why form not preview arrow keys. But anyway, if you need more low-level access to keyboard handling (in particular shortcuts handling) you can override form's ProcessCmdKey.
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.Left)
{
// your code here
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
arbiter
2009-06-26 12:50:44