按下按键的按键事件 [英] Key down event affected by buttons

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

问题描述

我在这里很新,我有一个C#应用程序的一些问题。
我想捕获键下拉事件。这不是一开始的问题,但是在我添加了一些按钮到窗体后,该窗体的按键事件将忽略箭头键,并将焦点从一个按钮移动到下一个按钮(启动事件)有没有

解决方案

设置 KeyPreview 属性在Form上为true。这将允许窗体看到除了子控件之外的keydown事件。



将此添加到您的窗体...

  protected override bool ProcessCmdKey(ref Message msg,Keys keyData)
{
if(keyData.Equals(Keys.Right))
{
MessageBox.Show(Right Key Pressed!);
}

return base.ProcessCmdKey(ref msg,keyData);
}


I'm new around here and i have a little problems with a C# application. I want to capture the key down event. This wasn't a problem at first but after i added some buttons to the form, the key down event of the form ignores the arrow keys and moves the focus from one button to the next.(The key up event works) Is there a way to stop this and make them do something else when i hold the arrow keys?

解决方案

Set the KeyPreview property on the Form to true. That will allow the form to see the keydown event in addition to the child controls.

Add this to your Form ...

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
    if (keyData.Equals(Keys.Right))
    {
        MessageBox.Show("Right Key Pressed!");
    }

    return base.ProcessCmdKey(ref msg, keyData);
}

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

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