Menu Class

 

Represents the base functionality for all menus. Although ToolStripDropDown and ToolStripDropDownMenu replace and add functionality to the Menu control of previous versions, Menu is retained for both backward compatibility and future use if you choose.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

System.Object
  System.MarshalByRefObject
    System.ComponentModel.Component
      System.Windows.Forms.Menu
        System.Windows.Forms.ContextMenu
        System.Windows.Forms.MainMenu
        System.Windows.Forms.MenuItem

[<AbstractClass>]
[<ListBindableAttribute(false)>]
type Menu = 
    class
        inherit Component
    end

NameDescription
System_CAPS_protmethodMenu(MenuItem[])

Initializes a new instance of the Menu class.

NameDescription
System_CAPS_protpropertyCanRaiseEvents

Gets a value indicating whether the component can raise an event.(Inherited from Component.)

System_CAPS_pubpropertyContainer

Gets the IContainer that contains the Component.(Inherited from Component.)

System_CAPS_protpropertyDesignMode

Gets a value that indicates whether the Component is currently in design mode.(Inherited from Component.)

System_CAPS_protpropertyEvents

Gets the list of event handlers that are attached to this Component.(Inherited from Component.)

System_CAPS_pubpropertyHandle

Gets a value representing the window handle for the menu.

System_CAPS_pubpropertyIsParent

Gets a value indicating whether this menu contains any menu items. This property is read-only.

System_CAPS_pubpropertyMdiListItem

Gets a value indicating the MenuItem that is used to display a list of multiple document interface (MDI) child forms.

System_CAPS_pubpropertyMenuItems

Gets a value indicating the collection of MenuItem objects associated with the menu.

System_CAPS_pubpropertyName

Gets or sets the name of the Menu.

System_CAPS_pubpropertySite

Gets or sets the ISite of the Component.(Inherited from Component.)

System_CAPS_pubpropertyTag

Gets or sets user-defined data associated with the control.

NameDescription
System_CAPS_protmethodCloneMenu(Menu)

Copies the Menu that is passed as a parameter to the current Menu.

System_CAPS_protmethodCreateMenuHandle()

Creates a new handle to the Menu.

System_CAPS_pubmethodCreateObjRef(Type)

Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.(Inherited from MarshalByRefObject.)

System_CAPS_pubmethodDispose()

Releases all resources used by the Component.(Inherited from Component.)

System_CAPS_protmethodDispose(Boolean)

Disposes of the resources, other than memory, used by the Menu.(Overrides Component.Dispose(Boolean).)

System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Releases unmanaged resources and performs other cleanup operations before the Component is reclaimed by garbage collection.(Inherited from Component.)

System_CAPS_pubmethodFindMenuItem(Int32, IntPtr)

Gets the MenuItem that contains the value specified.

System_CAPS_protmethodFindMergePosition(Int32)

Returns the position at which a menu item should be inserted into the menu.

System_CAPS_pubmethodGetContextMenu()

Gets the ContextMenu that contains this menu.

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetLifetimeService()

Retrieves the current lifetime service object that controls the lifetime policy for this instance.(Inherited from MarshalByRefObject.)

System_CAPS_pubmethodGetMainMenu()

Gets the MainMenu that contains this menu.

System_CAPS_protmethodGetService(Type)

Returns an object that represents a service provided by the Component or by its Container.(Inherited from Component.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodInitializeLifetimeService()

Obtains a lifetime service object to control the lifetime policy for this instance.(Inherited from MarshalByRefObject.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone(Boolean)

Creates a shallow copy of the current MarshalByRefObject object.(Inherited from MarshalByRefObject.)

System_CAPS_pubmethodMergeMenu(Menu)

Merges the MenuItem objects of one menu with the current menu.

System_CAPS_protmethodProcessCmdKey(Message, Keys)

Processes a command key.

System_CAPS_pubmethodToString()

Returns a String that represents the Menu control.(Overrides Component.ToString().)

NameDescription
System_CAPS_pubfieldSystem_CAPS_staticFindHandle

Specifies that the FindMenuItem method should search for a handle.

System_CAPS_pubfieldSystem_CAPS_staticFindShortcut

Specifies that the FindMenuItem method should search for a shortcut.

NameDescription
System_CAPS_pubeventDisposed

Occurs when the component is disposed by a call to the Dispose method. (Inherited from Component.)

This class is the base class for the MainMenu, MenuItem, and ContextMenu classes. You cannot create an instance of this class. The menus for an application consist of MenuItem objects. These can contain other MenuItem objects, representing submenu items. The MenuItem objects can be stored in a MainMenu for display as an entire menu structure for a form or a ContextMenu that is used to display shortcut menus. This class provides functionality that is common for all the menu classes.

Unlike many base classes, the Menu class uses its derived classes to define many of its properties. If you are using your menu in a multiple-document interface (MDI) application, you can use the MdiListItem property to specify a MenuItem that displays a list of open MDI child forms in your application. The MenuItems property contains a list of MenuItem objects stored in the menu class. For a MainMenu or ContextMenu, this property contains all the MenuItem objects that are displayed. For a MenuItem, the MenuItems property represents the submenu items associated with it.

In addition to the properties that are provided for all the derived menu classes, the Menu class also provides methods, such as CloneMenu and MergeMenu, that enable you to create new menus from existing menus, and also merge two menu structures together.

The Menu class also defines the nested class Menu.MenuItemCollection. This class defines the collection of MenuItem objects used by the MenuItems property. You can use the methods of the Menu.MenuItemCollection class to add and remove menu items from a MainMenu, ContextMenu, or MenuItem.

The following code example uses the derived class, MenuItem, to create a menu structure for a form. The example code adds a MenuItem to represent the top-level menu item, adds a submenu item to it for selecting a font size, and then adds two submenu items to that menu item that represent large and small font choices in an application. The example requires that there is a MainMenu object named mainMenu1 and four MenuItem objects named menuItem1, menuItem2, menuItem3, and menuItem4.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 1.1

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show: