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

From Xojo Documentation

(Redirected from MenuItem.Constructor(Text as String, Tag as Variant))
You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!


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.

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"))