Go back key to go back to previous form

I want to go back to the previous form in C # using the backspace key. I am using the KeyDown event on a form to check the backspace key. but the form does not detect any keypress event.

How can I achieve this?

private void History_P_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyData.ToString() == "Back")
        MessageBox.Show("Back button pressed");
}

      

where History_P is the name of the form.

+3


source to share


1 answer


You need to include the property KeyPreview

in Form

.



With this feature keystroke (all events KeyUp

, KeyDown

, KeyPressed

) is first captured Form

and then transmitted to the control element, which is focused at this point, unless you change the setting KeyPressEventArgs.Handled

value true

.

+3


source







All Articles