KeyDown 事件不会使用 Enter 键在 ContextMenuStrip 上触发? [英] KeyDown event doesn't fire on ContextMenuStrip with enter key?

查看:25
本文介绍了KeyDown 事件不会使用 Enter 键在 ContextMenuStrip 上触发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.NET:我有一个上下文菜单条,我想使用键盘键来处理.

.NET : I have a Context menu strip that I want to handle using keyboard keys.

我有以下事件处理程序:

I have the following event handler:

Private Sub ContextMenuEnterKey(ByVal Sender As Object, ByVal E As KeyEventArgs) Handles ContextMenu.KeyDown

    If E.KeyValue = Keys.Enter Then
        'Do some staff
    End If

End Sub

使用除 EnterKey 以外的其他键可以正确触发事件.

The events fires correctly with other keys except EnterKey.

有人知道这是怎么回事吗?

Does anyone know what's wrong with that ?

推荐答案

您将处理程序绑定到哪个控件的 KeyDown 事件?在表单设计器中?KeyDown 事件甚至没有为 ContextMenuStrip 显示(至少在 VS2012 中,我正在使用 C#...)我可以在代码中绑定到 in,但是这似乎没有任何影响.

To which control's KeyDown event are you binding your handler? In the Forms designer the ? KeyDown event isn't even shown for ContextMenuStrip (at least here in VS2012, and I'm working in C#...) I can bind to in in code, but this doesn't seem to have any effect.

但是在 ContextMenuStrip 中有一个 PreviewKeyDown 事件,它会在上下文菜单中的每次击键时调用,也为 Enter 键调用.也许这可以帮助您?

But there is a PreviewKeyDown event in ContextMenuStrip which gets called for every keystroke within the context menu, also for the Enter key. Maybe this can help you?

这篇关于KeyDown 事件不会使用 Enter 键在 ContextMenuStrip 上触发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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