Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Multiple MainMenu problem
 

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.

MigrationUser 1  Wednesday, March 05, 2003 1:24 AM
Isnt there a MainMenu property in the form class ?

foreach (Menu m in MyForm.MainMenu)
{
    m.some_method()
}
MigrationUser 1  Wednesday, March 05, 2003 11:36 AM
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.
MigrationUser 1  Tuesday, March 18, 2003 5:37 PM
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
MigrationUser 1  Tuesday, March 18, 2003 6:04 PM

You can use google to search for other answers

Custom Search

More Threads

• Combobox propeties window - click any DataBindings property and get an error.
• Details regarding UndoEngine Class in .NET
• How can i add a verb to a components designer from a different components designer
• MainMenu item and Controls.Remove()
• Office-style buttons
• CodeDom passing an enum to a method invoke
• UITypeEditor cannot find dependency dlls that are not in system32
• TabControl - Selecting Tab in Code problem
• Compilation in IDE: persist component state
• Custom component selection problem