Web Menus

From Xojo Documentation

A web app cannot have a menu bar like a desktop app, but it can have menus. Two places that menus are used are in Contextual menus for controls and for Menu Buttons on Toolbars.

In both cases, you use the WebMenuItem class to create your menu.

Below is a list of commonly used properties and methods for a Web Menu. Refer to WebMenuItem in the Language Reference for the complete list.


Tag - A Variant value that is associated with the specific menu.

Value - The text that is displayed for the menu.


Constructor - Use the Constructor to quickly create a menu with its text.

AddMenuitem - Adds a menu to a menu.


To add a contextual menu to a Button, you create the menu in the Shown event handler for the control and assign it to the ContextualMenu property of the Button:

Var menu As New WebMenuitem

menu.AddMenuItem("Item 1")
menu.AddMenuItem("Item 2")

Me.ContextualMenu = menu

The user can now right-click on the button to show the menu. The ContextualMenuAction event is available for all web controls.

To determine which menu was selected, use this code in the ContextualMenuSelected event handler of the Button:

Select Case hitItem.Caption
Case "Item 1"
MessageBox("Item 1 selected.")
Case "Item 2"
MessageBox("Item 2 selected.")
End Select

You can also created submenus by adding them to an existing menu. This code creates a Dark Wizards menu and adds Sauron and Saruman menus to it:

Var myMenu As New WebMenuItem

Var menuItem1 As New WebMenuItem("Dark Wizards")
Var subMenuItem1 As New WebMenuItem("Sauron")
Var subMenuItem2 As New WebMenuItem("Saruman")

Me.ContextualMenu = myMenu

Example Projects

These projects demonstrate how you can use menus:

  • Examples/Web/Menus/WebToolbarMenu

See Also

WebMenuItem class; UserGuide:Web Toolbar topic