Multiple MainMenu problem

I have a Form with 3 MainMenus on it. I am trying to make as follows: 

   foreach menu in "MenuCollection" 
     menu.some_method 

My Problem is that I do not know where the "MenuCollection" is. 
I cannot create the collection manually. 
I know that all controls on a Form are in Form.Controls, but MainMenu is not. 

To which collection my menus belong to  

Thanks in advance.



Answer this question

Multiple MainMenu problem

  • bllua

    Isnt there a MainMenu property in the form class 

    foreach (Menu m in MyForm.MainMenu)
    {
        m.some_method()
    }

  • Fallendown

    It is important to understand that there are two basic buckets of "things" you can add to a Form or UserControl.  The first bucket is Controls.  Things like Buttons, StatusBars, and Panels are all Controls that can be positioned on your Form.  The second bucket is Components.  Menus (MenuItems, Context, and Main), Timers, and ToolTips are all examples of Components.  Notice that Components appear in the ComponentTray (beneath your Form or UserControl) when you add them from the toolbox.

    So, in your above post, you are correct: Form has a ControlCollection and all Controls are automatically added to this collection.  Since things such as Menus or Timers are Components - they are not added to the ControlCollection.

    You have a couple of options if you want to enumerate through all the MainMenus on your Form: 
    1) Manually do so.  In other words: have explicit code for each MainMenu.
    2) Add the MainMenus to a list or collection yourself.  You could use an ArrayList object.
    3) If you wanted to get tricky, you could use the Reflection classes to discover all the MainMenus that were related to your Form.

    Good luck.

  • live cricket audio commentary

    Hi, Evgeni

    In a Form you have only one active MainMenu at a time and it is reachable through the "Form.Menu" property(get and set)
    The best (and easiest) way to put them in a list is to use the ArrayList object

    Cheers,
    Gogou

  • Multiple MainMenu problem