Export (0) Print
Expand All

Menu.IsParent Property

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

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public virtual bool IsParent { get; }
/** @property */
public boolean get_IsParent ()

public function get IsParent () : boolean

Property Value

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

You can use this method to determine whether any MenuItem objects are assigned to this menu. This is equivalent to checking for a null reference (Nothing in Visual Basic) in the MenuItems property.

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.

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;
    }    
}

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

    menuItem1.set_Text("&File");
    menuItem2.set_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.get_IsParent()) {
        // Set the RightToLeft property for mainMenu1.
        mainMenu1.set_RightToLeft(get_RightToLeft().Yes);

        // Bind the MainMenu to Form1.
        set_Menu(mainMenu1);
    }
} //CreateMyMainMenu

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft