Menu.MenuItemCollection.Add Method (String, MenuItem)
[Visual Basic] Overloads Public Overridable Function Add( _ ByVal caption As String, _ ByVal items() As MenuItem _ ) As MenuItem [C#] public virtual MenuItem Add( string caption, MenuItem items ); [C++] public: virtual MenuItem* Add( String* caption, MenuItem* items ); [JScript] public function Add( caption : String, items : MenuItem ) : MenuItem;
- The caption of the menu item.
- An array of MenuItem objects that this MenuItem will contain.
A MenuItem that represents the menu item being added to the collection.
A MenuItem can only be contained in one menu at a time, and cannot be added more than once to the same menu. To reuse a MenuItem in more than one menu, use the CloneMenu method of the MenuItem class. To remove a MenuItem that you have previously added, use the Remove method.
This version of the Add method allows you to specify a caption for the menu item and a delegate that will handle its Click event. You can use this version of the Add method if your application already has an event handler to handle the Click event. This version of the method also allows you to specify an array of previously created MenuItem objects that you want to add to the collection. You can use this feature to reuse existing MenuItem objects that have been cloned using the CloneMenu method. If the items parameter is not empty or a null reference (Nothing in Visual Basic), the MenuItem being added to the collection will contain submenu items.
Note The Click event is not raised for a MenuItem that contains submenu items.
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family