按esc键停止调试

时间:2016-11-17 06:09:12

标签: vb.net debugging

我有一张表格。我想通过按下退出键关闭表单我也希望调试停止。我通过点击按钮关闭这里是代码

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

1 个答案:

答案 0 :(得分:0)

这是一个简单的解决方案:

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

希望得到这个帮助。