2016-11-17 186 views
0

我有一種形式。我想按Esc鍵關閉窗體我也想調試要stop.I我點擊此處按鈕關閉是代碼按Esc鍵停止調試

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 

回答

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 

希望這幫幫我。