C# / WinForms / 使主窗体的菜单可从子窗体访问(快捷键)

发布于 2024-12-21 06:30:59 字数 221 浏览 8 评论 0原文

我有一个带有菜单条的表单,其中有键盘快捷键。 键盘按预期工作。 然后我添加主窗体拥有的另一个窗体 (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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冰之心 2024-12-28 06:30:59

设置子窗体的 KeyPerview 属性为 True。

set property KeyPerview of child form True.

゛时过境迁 2024-12-28 06:30:59

您可以尝试以下操作 - 它将向子窗体添加菜单,但仍然在父窗体中运行事件处理程序:

        Form2 childForm = new Form2();
        childForm.Controls.Add(menuStrip1);
        childForm.MainMenuStrip = this.menuStrip1;
        childForm.Show();

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:

        Form2 childForm = new Form2();
        childForm.Controls.Add(menuStrip1);
        childForm.MainMenuStrip = this.menuStrip1;
        childForm.Show();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文