'C#: Trigger button click on keypress

How to trigger a button's click event when the desired key on the keyboard is pressed? Windows Forms C# .NET Framework on Visual Studio 2019



Solution 1:[1]

You can set KeyPreview to true, so that the window will receive the keypress events. You can then handle the event on Form level.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Thomas Weller