How to prevent user input from entering keyboard form (arrow keys) in C #

my usercontrol contains other controls that you can select, I would like to implement a way to navigate through the children using the arrow keys

The problem is that the parent controll intercepts the arrow keys and uses it to scroll its view, which I want to avoid. I want to decide to manage the contents of the control myself.

How can I control the standard behavior caused by the arrow keys?

Thanks in advance MTH

+3
source share
2 answers

IsInputKey(), , . , , UserControl, , OnKeyDown . ProcessCmdKey(), , . :

    protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
        switch (keyData) {
            case Keys.Left: MessageBox.Show("Left!"); break;
            case Keys.Right: MessageBox.Show("Right!"); break;
            default: return base.ProcessCmdKey(ref msg, keyData);
        }
        return true;  // used
    }
+3

OnKeyDown , , " " ( ).

, IsInputKey(), , :

    protected override bool IsInputKey(Keys keyData)
    {
        bool result = false;

        Keys key = keyData & Keys.KeyCode;

        switch (key)
        {
            case Keys.Up:
            case Keys.Down:
            case Keys.Right:
            case Keys.Left:
                result = true;
                break;

            default:
                result = base.IsInputKey(keyData);
                break;
        }

        return result;
    }
+3

All Articles