F10键没被抓住
我有一个 Windows.Form 并覆盖了 ProcessCmdKey。但是,这适用于除 F10 之外的所有 F 键。我试图寻找当我在表单上按 F10 时未调用 ProcessCmdKey 的原因。
有人可以给我一个提示,告诉我如何找到原因吗?
最好的问候,托马斯
I have a Windows.Form and there overriden ProcessCmdKey. However, this works with all of the F-Keys except for F10. I am trying to search for the reason why ProcessCmdKey is not called when I press F10 on my Form.
Can someone please give me a tip as to how I can find the cause?
Best Regards, Thomas
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
Windows 对 F10 的处理方式有所不同。 MSDN 上的“备注”部分给出了解释
Windows treats F10 differently. An explanation is given in the "Remarks" section here on MSDN
我刚刚在 .NET 4 上使用 Windows 窗体测试了此代码,并按预期收到了消息框。
I just tested this code with Windows Forms on .NET 4 and I got the message box as expected.
可能是我遇到了您的问题,所以尝试猜测:
您是否将 WindowsForm 的
KeyPreview
属性设置为true
?这将使 WindowsForm 能够在按键事件泵送到在该特定时刻将焦点保持在 UI 上的控件之前处理按键事件。
请告诉我是否有效。
问候。
May be I got your problem, so trying to guess:
Did you set
KeyPreview
property of your WindowsForm totrue
?This will enable possiblity to WindowsForm proceed keypress events before they pump to the control that holds the focus on UI in that precise moment.
Let me know if it works, please.
Regards.
就我而言,我试图将 e.key 与 system.windows.input.key.F10 匹配,但它不起作用(尽管 F1 到 F9 可以),
但是,我将其更改为
并且它起作用了。
In my case I was trying to match e.key to system.windows.input.key.F10 and it didn't not work (althougth F1 thru F9 did)
however, I changed it to
and it worked.
如果在 WPF 应用程序中遇到此问题,这篇博文展示了如何捕获 F10 键:
If running into this issue in a WPF app, this blog post shows how to capture the F10 key:
是的,由于这是一个特殊的键,您必须添加
它,告诉调用者您已经处理了它。
因此,您的代码可能如下所示:
Right, and as this is a special key you must add
it tells the caller that you handled it.
So, your code could look like: