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

From Xojo Documentation

Revision as of 15:28, 22 November 2019 by Gperlman (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Constructor

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.

Examples

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

Var editPasteSpecial As New MenuItem
editPasteSpecial.Text = "Paste Special..."
EditMenu.AddMenuAt(5, editPasteSpecial)

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

Var editPasteSpecial As New MenuItem("Paste Special...")
EditMenu.AddMenuAt(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.

Var m As MenuItem
Var mNew As MenuItem

m = Self.MenuBar
mNew = New MenuItem

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

Var submenu As New MenuItem("MySub")

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

mNew.AddMenu(submenu)

m.AddMenu(mNew)