防止通过按 Alt 键选择菜单条
我想要一些带有 alt 的快捷方式,但是当我按 alt 时,菜单条会被选中。我怎样才能禁用这种行为?
I would like to have some shortcuts with alt but when I press alt the menustrip gets selected. How can I disable this behaviour?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这就是为什么在 Windows 上不使用 ALT+快捷键。您不应尝试破坏本机系统行为。解决方案是选择不同的快捷键组合。
This is why, on Windows, you do not use ALT+key shortcuts. You should not attempt to subvert the native system behaviour. The solution is to choose a different shortcut combination.
我知道这个线程很旧,但我遇到了同样的问题。
一种部分解决方案是使用“SendKeys.Send”函数来模拟第二次按下 alt 键。例如,要模拟用户按“alt-0”:
sendkeys.send("%0")
这是有效的,因为按一次 Alt 键会激活菜单条,但第二次按则会停用它。
唯一的问题是,这也会欺骗软件认为用户松开了 Alt 键。因此,如果您希望能够在按住 Alt 键的同时按其他键,则它不起作用。
由于 Alt 键触发了 menustrip.activate 事件,似乎应该有某种方法可以在代码中触发 menustrip.deactivate 事件,而无需模拟另一个 Alt 键按下,但我不知道如何做到这一点。 ..
I know this thread is old, but I am running into the same problem.
One partial solution is to use the "SendKeys.Send" function to simulate a second press of the alt key. For example, to simulate the user pressing "alt-0":
sendkeys.send("%0")
This works because pressing the Alt-key once activates the menu strip, but pressing it a second time deactivates it.
The only problem is, this also tricks the software into thinking that the user let go of the Alt- key. So it doesn't work if you want to be able to press and hold the Alt-key while pressing some other keys.
Since the Alt-key triggers the menustrip.activate event, it seems there should be someway to trigger the menustrip.deactivate event in code without the hack of simulating another Alt-key press, but I can't figure out how to do that...