0

I have a 2-d array of my own controls (derived from UserControl) on a panel in a Windows form. I would like the arrow keys to navigate in 2-dimensions, but the arrow keys get intercepted before I get to see them so I just get the default navigation (which goes through all of my controls as if they were in a single line. Can anyone tell me how to intercept the keystrokes and do my own handling? At the moment I'm overriding OnKeyPress on my own controls to try to catch the keypress, but the keypresses are not getting through. I've also tried adding

protected override bool IsInputChar(char charCode)
{
    if (charCode == (char)Keys.Up || charCode == (char)Keys.Down || charCode == (char)Keys.Left || charCode == (char)Keys.Right) return true;
    else return base.IsInputChar(charCode);
}

both to my controls and to the form, but it makes no difference (that code isn't seeing the keypresses either). I can only think it's being caught at the level of the panel that my controls are on, but I can't see a direct way of adding an IsInputChar handler to it. Do I have to subclass the panel, is there another way of doing it, or am I missing the point altogether?

2
Contributors
1
Reply
3
Views
6 Years
Discussion Span
Last Post by Momerath
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.