Menu.IsParent 属性

定义

获取一个值,通过该值指示此菜单是否包含任何菜单项。Gets a value indicating whether this menu contains any menu items. 此属性是只读的。This property is read-only.

public:
 virtual property bool IsParent { bool get(); };
[System.ComponentModel.Browsable(false)]
public virtual bool IsParent { get; }
member this.IsParent : bool
Public Overridable ReadOnly Property IsParent As Boolean

属性值

如果此菜单包含 true 对象,则为 MenuItem;否则为 falsetrue if this menu contains MenuItem objects; otherwise, false. 默认值为 falseThe default is false.

属性

示例

下面的代码示例创建一个具有两个 MenuItem 对象的 MainMenuThe following code example creates a MainMenu with two MenuItem objects. 然后,它使用 IsParent 属性来确定 mainMenu1 是否包含菜单项。It then uses the IsParent property to determine whether mainMenu1 contains menu items. 如果条件计算 true,则将 RightToLeft 属性设置为 true,并将主菜单绑定到 FormIf the condition evaluates true, it sets the RightToLeft property to true and binds the main menu to the Form. 此示例要求创建一个名为 Form1FormThis 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 = gcnew MenuItem;
      MenuItem^ menuItem2 = gcnew MenuItem;
      menuItem1->Text = "&File";
      menuItem2->Text = "&Edit";

      // Create a MainMenu and assign MenuItem objects.
      array<MenuItem^>^menuMenu1Items = {menuItem1,menuItem2};
      MainMenu^ mainMenu1 = gcnew MainMenu( menuMenu1Items );

      // 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.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 Sub CreateMyMainMenu()
    ' Create two MenuItem objects and assign to array.
    Dim menuItem1 As New MenuItem()
    Dim menuItem2 As New MenuItem()

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

    ' Create a MainMenu and assign MenuItem objects.
    Dim mainMenu1 As New MainMenu(New MenuItem() {menuItem1, menuItem2})

    ' Determine if mainMenu1 is currently hosted on the form.
    If (mainMenu1.IsParent) Then
        ' Set the RightToLeft property for mainMenu1.
        mainMenu1.RightToLeft = RightToLeft.Yes
        ' Bind the MainMenu to Form1.
        Menu = mainMenu1
    End If

End Sub

注解

您可以使用此方法来确定是否有任何 MenuItem 对象分配到此菜单。You can use this method to determine whether any MenuItem objects are assigned to this menu. 这等效于检查 MenuItems 属性中的 nullThis is equivalent to checking for null in the MenuItems property.

安全性

SecurityPermission
用于处理非托管代码。for operating with unmanaged code. 关联的枚举: UnmanagedCodeAssociated enumeration: UnmanagedCode

适用于

另请参阅