Reputation:
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?
Upvotes: 0
Views: 572
Reputation: 806
You should Focus itself somewhere in the code to use ProcessCmdKey properly.
Upvotes: 0
Reputation: 9575
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);
}
Upvotes: 0
Reputation: 57468
Take a look at this SO question.
Is KeyPreview on? What control has focus?
Upvotes: 1