使用esc键关闭vb.net中的表单 [英] use esc key for closing form in vb.net

查看:112
本文介绍了使用esc键关闭vb.net中的表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在VS2008中使用vb.net窗口应用程序.

如何使用Esc键使用vb.net关闭表单.
任何代码或想法,将不胜感激...

谢谢
mukesh

Hi All,

I m using vb.net window application in VS2008.

How to use Esc key for closing form using vb.net.
any code or idea that will be appreciate......

thanks
mukesh

推荐答案

2选项:

1.在窗体设计器或代码中,将Form.CancelButton属性设置为取消"按钮.然后,当按下取消"按钮或单击退出"键(或即使关闭了对话框)时,窗体的DialogResult将为"DialogResult.Cancel".

2.使用keyDown事件并捕获KeyCode:
2 Options:

1. In your Forms designer or in your code, set the Form.CancelButton property to your "Cancel" button. Then, when the Cancel button is pressed, or the Escape key is clicked (or even if the Dialog is closed) then the DialogResult of the form will be "DialogResult.Cancel."

2. Use keyDown event and trap KeyCode:
Private Sub Form2_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
    If e.KeyCode = Keys.Escape Then Me.Close()
End Sub



试试吧!



Try!


这篇关于使用esc键关闭vb.net中的表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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