我的主菜单在哪里?

发布于 2024-12-26 12:53:10 字数 230 浏览 2 评论 0原文

菜单运行良好。生成成员已打开。问题是我试图在代码中操作它(放入一些动态项目),但我找不到它。

MainMenuStrip 为 null。菜单为。它不能位于控件中,因为它不是从 Control 继承的。

它在哪里???

只是为了澄清:我希望通过代码找到菜单,而不是简单地知道组件的名称。我想获取传入的任何表格并找到它。

The menu works fine. GenerateMember is on. The problem is that I'm trying to manipulate it in code (to put in a few dynamic items) and I can't find it.

MainMenuStrip is null. Menu is null. It can't be in controls because it doesn't inherit from a Control.

Where is it???

Just to make it clear: I'm looking to find the menu via code, not by simply knowing the name of the component. I want to take any form passed in and find it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

我的鱼塘能养鲲 2025-01-02 12:53:10

您可以尝试一下(假设只有一个 MenuStrip):

public static MenuStrip FindMenuStrip(Form fromForm) {
  return fromForm.Controls.OfType<MenuStrip>().FirstOrDefault();
}

You can try this (assuming only one MenuStrip):

public static MenuStrip FindMenuStrip(Form fromForm) {
  return fromForm.Controls.OfType<MenuStrip>().FirstOrDefault();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文