Menu.IsParent Menu.IsParent Menu.IsParent Menu.IsParent Property

定义

获取一个值,通过该值指示此菜单是否包含任何菜单项。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

属性值

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

示例

下面的代码示例将创建MainMenu具有两个MenuItem对象。The 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. 此示例要求具有Form创建名为Form1This 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. 这相当于检查nullMenuItems属性。This is equivalent to checking for null in the MenuItems property.

安全性

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

适用于

另请参阅