MenuItem.Append

From Xojo Documentation

Method

MenuItem.Append(Item as MenuItem)

New in 5.0

Supported for all project types and targets.

Appends the passed MenuItem to the menu. You can append a Separator by passing the class constant MenuItem.TextSeparator. Used to build a dynamic menu.

Sample Code

The following code creates a contextual menu in the ConstructContextualMenu event of any Window or RectControl. This event passes in the parameter base as MenuItem.

base.Append(New MenuItem("Import"))
base.Append(New MenuItem("Export"))
base.Append(New MenuItem(MenuItem.TextSeparator))

base.Append(New MenuItem("Cut"))
base.Append(New MenuItem("Copy"))
base.Append(New MenuItem("Paste"))
Return True // display the contextual menu

The following code creates a hierarchical menu that is added to the main menubar. It is in the Open event of the App or the window. It’s easiest to create menus and menuitems using the built-in Menu Editor and enable the MenuItems using the AutoEnable property. Use code for cases such as dynamic menus and contextual menus.

Dim m, mNew As MenuItem
m = Self.MenuBar
mNew = New MenuItem

mNew.Text = "Fonts"
mNew.Name = "Fonts"

mNew.Append(New MenuItem("TestOne"))
mNew.Append(New MenuItem("Testtwo"))
mNew.Append(New MenuItem("Testthree"))

mNew.Append(New MenuItem( "-" ))

Dim submenu As New MenuItem("MySub")
submenu.Append(New MenuItem("submenu One"))
submenu.Append(New MenuItem("submenu Two"))
submenu.Append(New MenuItem("submenu three"))

m.Append(mNew)
mNew.Append(submenu)