DekGenius.com
[ Team LiB ] Previous Section Next Section

Menumarshal by reference, disposable

System.Windows.Forms (system.windows.forms.dll)abstract class

This System.ComponentModel.Component is the abstract base for ContextMenu, MainMenu, and MenuItem classes. It provides most of the functionality of each of these classes but cannot be instantiated itself.

You can add MenuItem objects to the menu through the MenuItems collection. A MenuItem itself can contain further MenuItem objects, to allow for cascading child menus. You can determine if the menu has any children through the IsParent property.

You can also determine which menu item is a special MdiListItem—an item that will display a list of MDI child forms as a child menu. This is a read-only property—you set it through the MenuItem.MdiList property.

The Menu may be hosted in either a ContextMenu or a MainMenu, and you can determine which through the GetContextMenu() and GetMainMenu() methods.

Finally, there is a MergeMenu() method. This merges two menus together (performed automatically for MDI child menus). There is nothing to stop you from using it for your own menu management, however. It is particularly useful where you have a UI plug-in architecture, where various components provide their own little bit of menu structure that you can merge in to the overall menu hierarchy. To control the merge, specify the MenuItem.MergeOrder and MenuItem.MergeType properties (see MenuItem for more information on this).

public abstract class Menu : System.ComponentModel.Component {
// Protected Constructors
   protected Menu(MenuItem[ ] items);
// Public Static Fields
   public const int FindHandle;  // =0
   public const int FindShortcut;  // =1
// Public Instance Properties
   public IntPtr Handle{get; }
   public virtual bool IsParent{get; }
   public MenuItem MdiListItem{get; }
   public MenuItemCollection MenuItems{get; }
// Public Instance Methods
   public MenuItem FindMenuItem(int type, IntPtr value);
   public ContextMenu GetContextMenu();
   public MainMenu GetMainMenu();
   public virtual void MergeMenu(Menu menuSrc);
   public override string ToString();  // overrides System.ComponentModel.Component
// Protected Instance Methods
   protected void CloneMenu(Menu menuSrc);
   protected virtual IntPtr CreateMenuHandle();
   protected override void Dispose(bool disposing);  // overrides System.ComponentModel.Component
   protected int FindMergePosition(int mergeOrder);
   protected internal virtual bool ProcessCmdKey(ref Message msg, Keys keyData);
}

Hierarchy

System.Object System.MarshalByRefObject System.ComponentModel.Component(System.ComponentModel.IComponen, System.IDisposable) Menu

Subclasses

ContextMenu, MainMenu, MenuItem

Returned By

System.Windows.Forms.Design.IMenuEditorService.GetMenu(), MenuItem.Parent, ToolBarButton.DropDownMenu

Passed To

System.Windows.Forms.Design.IMenuEditorService.SetMenu(), MenuItemCollection.MenuItemCollection(), ToolBarButton.DropDownMenu

    [ Team LiB ] Previous Section Next Section