Menu.IsParent Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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; }
[<System.ComponentModel.Browsable(false)>]
member this.IsParent : bool
Public Overridable ReadOnly Property IsParent As Boolean
Property Value
true
if this menu contains MenuItem objects; otherwise, false
. The default is false
.
- Attributes
Examples
The following code example creates a MainMenu with two MenuItem objects. It then uses the IsParent property to determine whether mainMenu1
contains menu items. If the condition evaluates true
, it sets the RightToLeft property to true
and binds the main menu to the Form. 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
Remarks
You can use this method to determine whether any MenuItem objects are assigned to this menu. This is equivalent to checking for null
in the MenuItems property.