This documentation is archived and is not being maintained.

MenuItem.Parent Property

Gets a value indicating the menu that contains this menu item.

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

public Menu Parent { get; }

Property Value

Type: System.Windows.Forms.Menu
A Menu that represents the menu that contains this menu item.

You can use this property to obtain the Menu object for a submenu. You can cast the Menu object returned by this property to a MenuItem object to manipulate it.

In this example, you create a main menu and a top-level menu item, menuItem1 (File). You also create two menu items, menuItem2 (New) and menuItem3 (Open), and add them to the menu item list of menuItem1. Then you check to see if menuItem3 has got a parent menu, which is true, and display the information of this parent menu in message box. This example requires that you have created a Form named Form1.

		public void CreateMyMenuItems()
			// Craete a main menu object.
			MainMenu mainMenu1 = new MainMenu();

			// Create three top-level menu items.
			MenuItem menuItem1 = new MenuItem("&File");
			MenuItem menuItem2 = new MenuItem("&New");
			MenuItem menuItem3 = new MenuItem("&Open");

			// Add menuItem1 to the main menu.

			// Add menuItem2 and menuItem3 to menuItem1.

			// Check to see if menuItem3 has a parent menu.
			if (menuItem3.Parent != null)
						".", "Parent Menu Information of menuItem3"); 
				MessageBox.Show("No parent menu."); 

			// Assign mainMenu1 to the form.
			this.Menu = mainMenu1;			

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.