始终以基本形式处理 PreviewKeyDown 事件 [英] Always handle the PreviewKeyDown event in a base form

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

问题描述

我们需要在基本表单中处理这个事件,而不管当前有哪些控件具有焦点.我们有几个全局键命令,无论控制焦点如何,它们都需要工作.

We need to handle this event in the base form, regardless of which controls currently have focus. We have a couple of global key commands that need to work regardless of control focus.

这是通过正常处理表单中的 PreviewKeyDown 事件来实现的.当我们向表单添加用户控件时,该事件不再触发.

This works by handling the PreviewKeyDown event in the form normally. When we add a user control to the form, the event no longer fires.

我在这里遗漏了一些微不足道的东西吗?还是需要先处理用户控件中的事件?

Am I missing something trivial here? Or do we need to handle the event in the user control first?

感谢您的帮助!

感谢因子.当我有更多时间时:) 我会让它正常"工作!

Thanks Factor. When I get more time :) I'll get it working 'properley'!

推荐答案

我们最终做到了:

我通过以下设置找到了一个隐藏菜单项的解决方法:

I found a workaround for this by setting up a hidden menu item by setting:

ToolStripMenuItem.Visible = false

(感谢这篇文章).

似乎总是在表单的主菜单中搜索您的快捷键组合.无论哪个控件具有焦点,这都有效

It appears that the Main Menu of a form always gets searched for your shortcut key combination. This works regardless of whick control has focus

这篇关于始终以基本形式处理 PreviewKeyDown 事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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