Backspace key to return previous form

I want to return to previous form in C# using backspace key. I am using KeyDown event on form to check for backspace key . but the form is not detecting any key down 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 form name.


You need to enable the KeyPreview property on the Form.

With this property the key being pressed (all KeyUp, KeyDown, KeyPressed events) will first be caught by the Form and is then passed on to the control that is focused at that moment, unless you set the KeyPressEventArgs.Handled to true.

Category:c# Time:2018-12-25 Views:1
Tags: winforms

Related post

Copyright (C), All Rights Reserved.

processed in 3.125 (s). 13 q(s)