I
I
ITLDS2019-07-08 17:31:44
C++ / C#
ITLDS, 2019-07-08 17:31:44

The OnKeyDown method does not work. Where is the mistake?

I need to handle the KeyDown event for the arrows. KeyDown is not processed when clicking on the arrows, so I specify which keys to respond to through IsInputKey and then work with this in OnKeyDown:

protected override bool IsInputKey(Keys keyData)
        {
            switch (keyData)
            {
                case Keys.Right:
                case Keys.Left:
                case Keys.Up:
                case Keys.Down:
                    return true;
            }
            return base.IsInputKey(keyData);
        }
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);
            MessageBox.Show("efg");
        }

But nothing comes out. What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Planet_93, 2019-07-09
@ITLDS

See how switch works. And make sure that this event comes to the method using a breakpoint.

Console.WriteLine("Нажмите Y или N");
string selection = Console.ReadLine();
switch (selection)
{
    case "Y":
        Console.WriteLine("Вы нажали букву Y");
        break;
    case "N":
        Console.WriteLine("Вы нажали букву N");
        break;
    default:
        Console.WriteLine("Вы нажали неизвестную букву");
        break;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question