Closing form using escape key
Hi!
I need the key escape to close the form that is being used at the moment. I've used keypressed property = key.escape. The problem is that I got a main form which is a parent of the rest and when I press escape it understands that I want to close the parent form instead of the child form (which is opened) and it closes the parent form (and therefore the child form too).
How can I make it close only the form that is opened and not the parent one?
Thanks for your help, folks!
Re: Closing form using escape key
This worked fine for me.. It unloaded Form2 while Form1 stayed open
Code:
Private Sub Form2_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If e.KeyCode = Keys.Escape Then Me.Close()
End Sub
Re: Closing form using escape key
do you have a close button on the form?? if so, in the FORMS properties, set the CancelButton property to that commandbutton, and when you hit escape, it will be the same as clicking that button... likewise the form has an acceptbutton property for when you hit enter
these properties used to be on the button level, but in .net they have been moved (rightfully so) to the form level
Re: Closing form using escape key
Alright, great linking the close button woks great, thanks!