C# / WinForms / 使主窗体的菜单可从子窗体访问(快捷键)
我有一个带有菜单条的表单,其中有键盘快捷键。 键盘按预期工作。 然后我添加主窗体拥有的另一个窗体 (child.Owner = main)。 当此表单具有焦点时,我无法访问主表单上的菜单(使用键盘)。
我想这是预期的行为,但是如果我想在子窗体具有焦点时允许访问主窗体上的菜单,我该怎么做?
我不想手动设置和处理所有键盘事件并将它们绑定到正确的操作,这是唯一的方法吗?
干杯, 方程
I've got a form with a menu strip that has keyboard shortcut's.
Keyboard works as expected.
Then I add another form that is owned by the main form (child.Owner = main).
When this form has focus I can't access the menu on the main form (using the keyboard).
I guess this is expected behavior, but what if I wanted to allow access to the menu on the main form when the child form have focus, how do I do that?
I don't feel like manually set up and handle all keyboard events and bind them to the correct action, is this the only way?
Cheers,
Eq
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
设置子窗体的 KeyPerview 属性为 True。
set property KeyPerview of child form True.
您可以尝试以下操作 - 它将向子窗体添加菜单,但仍然在父窗体中运行事件处理程序:
You can try out the following - it will add the menu to the child form, but still run the event handlers in the parent form: