MenuItem.Constructor(Text as String, Tag as Variant)

From Xojo Documentation

MenuItem.Constructor(Text as String, [Tag as Variant=Nil])

Creates a new MenuItem that uses the passed string as its Text property and optionally adds the passed Tag.


This example inserts a new item in the Edit menu with the text "Paste Special..." just below the Paste item.

Dim editPasteSpecial As New MenuItem
editPasteSpecial.Text = "Paste Special..."
EditMenu.Insert(5, editPasteSpecial)

Using this constructor, you can rewrite the code above more concisely:

Dim editPasteSpecial As New MenuItem("Paste Special...")
EditMenu.Insert(5, editPasteSpecial)

This example illustrates how you can manipulate the menu bar at run time. By adding this example to the open even of a window it will add a new menu to menubar when the window opens.

Dim m As MenuItem
Dim mNew As MenuItem

m = Self.MenuBar
mNew = New MenuItem

mNew.Text = "MyMenuText"
mNew.Name = "MyMenuName"

Dim submenu As New MenuItem("MySub")

submenu.Append(New MenuItem("Submenu One"))
submenu.Append(New MenuItem("Submenu Two"))
submenu.Append(New MenuItem("Submenu three"))