取消KeyDown事件 [英] Cancel KeyDown Event

查看:585
本文介绍了取消KeyDown事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void MainForm_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                switch (e.KeyCode)
                {
                    case Keys.Up:
                        Engine.GearUp();
                        break;

...





当engine.gearup()工作时,我需要取消(或者做其他我不太确定的事情)keydown事件所以用户无法按下任何键,直到gearup()完成它的工作



我尝试e.handled和e.SuppressKeyPress,它没有为我工作..Googled一点,无法找到任何东西..任何帮助将不胜感激



While engine.gearup() is working, I need to cancel(or do something else i am not really sure about it) keydown event so user can not be able to press anymore keys until gearup() has done it''s work

I tried e.handled and e.SuppressKeyPress and it didnt work for me ..Googled a bit and couldnt find anything..Any help will be appreciated

推荐答案

未经测试,但是不要处理事件,请尝试覆盖引发事件 OnKeyDown 的方法,并且只在您调用 base.OnKeyDown 时我想允许按键。
Not tested, but instead of handling the event, try overriding the method that raises the event OnKeyDown and only calling base.OnKeyDown when you want to allow the key press.


这篇关于取消KeyDown事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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