Поделиться через


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

Значение свойства

trueЗначение , falseесли это меню содержит MenuItem объекты; в противном случае . Значение по умолчанию — false.

Атрибуты

Примеры

В следующем примере кода создается MainMenu два MenuItem объекта. Затем он использует IsParent свойство, чтобы определить, содержит ли mainMenu1 элементы меню. Если условие вычисляется true, оно задает RightToLeft свойство true и привязывает главное меню к нему Form. В этом примере требуется, чтобы у вас был Form созданный объект с именем 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 этому меню. Это эквивалентно проверке null в свойстве MenuItems .

Применяется к

См. также раздел