How to make An ESC ShortCut Key

capedech

Well-known member
Joined
Oct 29, 2008
Messages
62
Programming Experience
Beginner
I put MenuStrip in Form1, and make the visible = False
I tried to find "ESC" at ShortCutKeys in MenuStrip Properties, but couldn't find it.
Is there other way to make the ESC shortcut key ?
 
It is possible that key is reserved for other uses, like escaping/cancel various things, and that using it would conflict such default system uses. But if you see no problem using it you can for example set the child forms KeyPreview property to True and handle the KeyUp event for the form. Here you can call the menu items click handler (menuitem.PerformClick). For that menu item you can set "ESC" as ShortcutKeyDisplayString even though no shortcut really has been set. KeyUp sample:
VB.NET:
Private Sub Form3_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
    If e.KeyCode = Keys.Escape Then
        ExitToolStripMenuItem.PerformClick()
    End If
End Sub
 
Back
Top