Winforms are picky about the selected keyboard shortcut. The rule is that it must be a function key (F1-F12) or another key with Keys.Control or Keys.Alt . The bigger intention here is that you cannot accidentally replace a regular key that can be used, say, in a TextBox . The Escape button usually includes a dialog cancel button.
Keys.Escape pretty special; Alt + Escape and Ctrl + Escape cannot work, as they are global keyboard shortcuts in Windows.
Therefore, you cannot use the ShortcutKeys property; you need to recognize the Escape key in different ways. It runs easily in your Form class by overriding the ProcessCmdKey() method. Paste this code into the form:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if (keyData == Keys.Escape) { this.Close(); return true; } return base.ProcessCmdKey(ref msg, keyData); }
source share