(Winform)Keypress事件在创建另一个表单时不起作用 [英] (Winform) Keypress event not working when creating another form

查看:96
本文介绍了(Winform)Keypress事件在创建另一个表单时不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


目前在Windows窗体中处理项目这是一个场景,

Currently working on a project in Windows form This is the scenario,


我有Form 1,它在程序启动时初始化,当我按下"1"时。它创建另一个表单(表单2)显示它并隐藏表单1(此按键事件有效)

I have Form 1 which initializes on program start and when I press "1" it creates another form (Form 2) shows it and hides Form 1 (this keypress event works)


我在表单2中设置每当我按转义,它隐藏表单2然后创建表单1的另一个实例然后显示它,但问题是这个按键事件不起作用。

I set in Form 2 that whenever i press escape, it hides Form 2 and then creates another instance of Form 1 then shows it, but the problem is this keypress event wont work.


任何人都知道导致问题的原因以及解决方法是什么?

Anybody knows what causes the problem and how to fix it?

推荐答案

显示有关密钥处理的详细信息。

为了能够使用< Esc>关闭表单2,尝试添加一个按钮("关闭"),然后设置表单的
CancelButton 属性指向此按钮。然后处理该按钮的
单击事件,并添加 this.Close()

In order to be able to close the Form 2 using <Esc>, try adding a button ("Close"), then set the CancelButton property of the form to point to this button. Then handle the Click event of the button, and add this.Close().

按钮可以移到形式,如果你不想要它。


这篇关于(Winform)Keypress事件在创建另一个表单时不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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