Menu.IsParent Property

Definition

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

C#
[System.ComponentModel.Browsable(false)]
public virtual bool IsParent { get; }

Property Value

true if this menu contains MenuItem objects; otherwise, false. The default is false.

Attributes

Examples

The following code example creates a MainMenu with two MenuItem objects. It then uses the IsParent property to determine whether mainMenu1 contains menu items. If the condition evaluates true, it sets the RightToLeft property to true and binds the main menu to the Form. This example requires that you have a Form created that is named Form1.

C#
       public void CreateMyMainMenu()
       {
           // Create two MenuItem objects and assign to array.
           MenuItem menuItem1 = new MenuItem();
           MenuItem menuItem2 = new MenuItem();

           menuItem1.Text = "&File";
           menuItem2.Text = "&Edit";

           // Create a MainMenu and assign MenuItem objects.
           MainMenu mainMenu1 = new MainMenu(new MenuItem[] {
                       menuItem1,
                       menuItem2});
   
           // Determine whether mainMenu1 contains menu items.  
           if (mainMenu1.IsParent) 
           {
               // Set the RightToLeft property for mainMenu1.
               mainMenu1.RightToLeft = RightToLeft.Yes;
               // Bind the MainMenu to Form1.
               Menu = mainMenu1;
           }	
       }

Remarks

You can use this method to determine whether any MenuItem objects are assigned to this menu. This is equivalent to checking for null in the MenuItems property.

Applies to

Produkt Verzie
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 10

See also