当用户按下 Alt+X 时关闭程序 [英] Close program when the user presses Alt+X

查看:38
本文介绍了当用户按下 Alt+X 时关闭程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个学校的作业,当用户按下 Alt X 时,程序应该关闭.

I have an assignment from school where the program is supposed to close when the user presses Alt X.

我已经使用 Java 完成了这项工作,但那是很久以前的事了,我不记得我是如何做到的.你如何在 VB 中做到这一点?

I have done this using Java but that was a long time ago and I can't remember how I did it. How do you do it in VB?

感谢您的帮助

谢谢大家的帮助.

但我无法让它工作:

If e.KeyCode = Keys.Alt AndAlso e.KeyCode = Keys.X Then
    Application.Exit()
End If

推荐答案

像这样尝试(对于表单,请确保 KeyPreview=True):

Try it like this (and for a form, make sure KeyPreview=True):

Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles MyBase.KeyDown
  If e.Alt AndAlso e.KeyCode = Keys.X Then
    Application.Exit()
  End If
End Sub

这篇关于当用户按下 Alt+X 时关闭程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆