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?

Panels have a PreviewKeyDown event you can attach to. That might help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.