Search code examples
c#.netwinformsmenubar

Where is my main menu?


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.


Solution

  • You can try this (assuming only one MenuStrip):

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