Menu.IsParent 属性

定义

获取一个值,通过该值指示此菜单是否包含任何菜单项。 此属性为只读。

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

属性值

如果此菜单包含 MenuItem 对象,则为 true;否则为 false。 默认值为 false

属性

示例

下面的代码示例创建具有两MenuItemMainMenu 对象的 。 然后, IsParent 它使用 属性来确定是否 mainMenu1 包含菜单项。 如果条件计算 true为 ,它将 属性设置为 RightToLefttrue ,并将主菜单绑定到 Form。 此示例要求创建名为 FormForm1

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 对象。 这等效于在 属性中MenuItems检查 null

适用于

另请参阅