有谁能帮我理解如何在以下代码中设置快捷键?
它应该是Alt + X(退出是按钮的名称)。
我试过了cmd_Exit.text="&Exit"
,但它打印了“&”并没有设置快捷键。
Private Sub cmdExit_Click(sender As Object, e As EventArgs) Handles cmdExit.Click
'cmdExit.Capture()
Dim response = MsgBox("Are you sure you want to exit?", CType(MsgBoxStyle.YesNo + MsgBoxStyle.Exclamation, MsgBoxStyle), "Leaving?")
If response = MsgBoxResult.Yes Then 'if yes exit the application
Application.Exit()
End If
End Sub
答案 0 :(得分:7)
您可以检查是否正在使用keydown事件按下Alt + X,然后使用它调用exit子:
注意,您需要在主窗体中将KeyPreview设置为True
Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.X AndAlso e.Modifiers = Keys.Alt Then
e.Handled = True
cmdExit_Click(sender, e) 'or cmdExit.PerformClick()
End If
End Sub
答案 1 :(得分:0)
$apiContext->setConfig(
array(
'mode' => 'sandbox',
'log.LogEnabled' => true,
'log.FileName' => '../PayPal.log',
'log.LogLevel' => 'DEBUG', // PLEASE USE `INFO` LEVEL FOR LOGGING IN LIVE ENVIRONMENTS
)
(事件)Form1_KeyDown
set Form KeyPreview = True
答案 2 :(得分:0)
Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.X AndAlso e.Modifiers = Keys.Alt Then
e.Handled = True
cmdExit_Click(sender, e) 'or cmdExit.PerformClick()
End If
End Sub