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

Definizione

Ottiene un valore che indica se questo menu contiene voci di menu.Gets a value indicating whether this menu contains any menu items. Questa proprietà è di sola lettura.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

Valore della proprietà

true se questo menu contiene oggetti MenuItem; in caso contrario, false.true if this menu contains MenuItem objects; otherwise, false. Il valore predefinito è false.The default is false.

Esempi

L'esempio di codice seguente crea una MainMenu con due MenuItem oggetti.The following code example creates a MainMenu with two MenuItem objects. Quindi, utilizza il IsParent proprietà per determinare se mainMenu1 contiene voci di menu.It then uses the IsParent property to determine whether mainMenu1 contains menu items. Se la condizione viene valutata true, imposta le RightToLeft proprietà true e associa il menu principale per il Form.If the condition evaluates true, it sets the RightToLeft property to true and binds the main menu to the Form. In questo esempio è necessario disporre una Form creata denominata Form1.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 = 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

Commenti

È possibile usare questo metodo per determinare se eventuali MenuItem gli oggetti vengono assegnati a questo menu.You can use this method to determine whether any MenuItem objects are assigned to this menu. Ciò equivale al controllo della presenza null nella MenuItems proprietà.This is equivalent to checking for null in the MenuItems property.

Sicurezza

SecurityPermission
per operare con codice non gestito.for operating with unmanaged code. Enumerazione associata: UnmanagedCodeAssociated enumeration: UnmanagedCode

Si applica a

Vedi anche