关于按键代码检测的keydown事件 [英] about keydown event for key code detect

查看:83
本文介绍了关于按键代码检测的keydown事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个窗口窗体,它包含多个具有"Panel"类型的控件,
现在,我将KeyDown事件添加到此表单和控件中.

我发现表单的keydown可以提供向左/向右/向上/向下的按键检测,
但是,控件(面板)的keydown事件将不提供向左/向右/向上/向下
密钥检测,对吗?如果是,如何获得左/右/上/下
控制键按下事件的键代码?如果不是,那可能是什么问题?

感谢您在此问题上的全力支持.

I have a window form, and it includes several control with ''Panel'' type,
now I add KeyDown event to this form and control.

I found that the keydown of form can provide left/right/up/down key detect,
however, the keydown event of control (Panel) will not provide left/right/up/down
key detect, is that right ? If yes, how can I get the left/right/up/down
key code for control keydown event ? If not, what''s wrong it could be ?

Thanks of your fully support on this issue.

推荐答案

您好,

我认为您正在为控件(面板)搜索PreviewKeyDown-Event.

Hi,

I think you''re searching for PreviewKeyDown-Event for your Control (your panel).

private void panel1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
        {
            if (e.KeyCode == Keys.Left)
            {
                //do something
            }
        }



致以最诚挚的问候



With Best Regards


这篇关于关于按键代码检测的keydown事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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