How to capture a key pressed in C#

I have an application with Digit buttons and I want to capture the keystrokes typed and run the events of those buttons. I added an event of keypress in the window and tried to catch the typed key, but I could not.

Code:

private void CalculadoraDS2_KeyPress(object sender, KeyPressEventArgs e)
{
    if(e.KeyChar.GetType == '0')
    {
        btn0.PerformClick();
    }
}
Author: Matheus Miranda, 2018-03-01

1 answers

Follows Code:

if (e.KeyChar == (char)Keys.D0)
{
    //tecla 0 pressionada
    btn0.PerformClick();
    e.Handled = true;
}

For more information: here .

Complete list of all key codes Keys Enum: here .

 2
Author: Matheus Miranda, 2018-03-01 18:17:24