我目前正在为VB.NET中的项目编写代码,如果你点击" escape"按钮,你得到一个消息框说"这退出程序,你想离开吗? ' Y'或者' N'"。我会编写什么代码来使它成为如果你点击" Y"该计划结束?
这是我到目前为止所做的:
Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Escape Then
MsgBox("This button exits the program. Do you want to exit the program?")
If Button = e.KeyCode = Keys.Y Then
End
End If
End If
End Sub
答案 0 :(得分:1)
这将为您提供以下内容:
Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Escape Then
If MessageBox.Show("message", "caption", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
Close()
End If
End If
End Sub
屏幕截图显示按 Esc 按钮时的外观:
答案 1 :(得分:-1)
试试这个
{{1}}
答案 2 :(得分:-1)
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
Select Case e.KeyCode
Case Keys.Escape
Msgbox("Close",vbInformation)
Me.Close()
End Select
End Sub
希望这有助于作为指导。