Vikki_Purohit Vikki_Purohit - 1 year ago 88 Question

Stop Debugging by pressing esc key

I have one form. I want to close the form by pressing escape key i also want debugging to be stop.I am closing by clicking button here is the code

Private Sub Form2_Closing(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

Select Case MessageBox.Show("Are you sure you want to exit?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
Case Windows.Forms.DialogResult.Yes
Application.Exit() ' Close the form and also debugging
'nothing to do here the form is already closing
Case Windows.Forms.DialogResult.No
e.Cancel = True 'cancel the form closing event
'minimize to tray/hide etc here
End Select

End Sub

Answer Source

Here is one simple solution:

Private Sub Form2_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
     Select Case e.Key
               Case Key.Escape
               Case Else
                    ' do nothing
     End Select
End Sub

Hope this help.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download