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

From Xojo Documentation

Revision as of 19:16, 23 July 2021 by Gperlman (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!

Constructor

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

Creates a new DesktopMenuItem 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 DesktopMenuItem
editPasteSpecial.Text = "Paste Special..."
EditMenu.AddMenuAt(5, editPasteSpecial)

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

Var editPasteSpecial As New DesktopMenuItem("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 DesktopMenuItem
Var mNew As DesktopMenuItem

m = Self.MenuBar
mNew = New DesktopMenuItem

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

Var submenu As New DesktopMenuItem("MySub")

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

mNew.AddMenu(submenu)

m.AddMenu(mNew)