Xojo

GETTING STARTED

  • Introduction
  • QuickStarts
  • Tutorials
  • Using the IDE
  • Using the Xojo Language
  • Object-Oriented Programming
  • Examples
  • Debugging

TOPICS

  • Advanced features
  • Android
  • API design
  • Application deployment
  • Application structure
  • Build automation
  • Code management
  • Communication
  • Custom controls
  • Data processing
  • Databases
  • Debugging
  • Declares
  • File management
  • Graphics
  • iOS
  • Linux
  • Localizing your apps
  • macOS
  • Migrating from other development tools
  • Office Automation
  • OS information
  • Printing
  • Raspberry Pi
  • Text handling
  • Threading
  • User interface
    • Creating your own controls
    • Design tips
    • Desktop
    • Dynamically adding and removing controls
    • iOS
    • Playing movies and sound
    • Sharing event handlers with Control Sets
    • Supporting Dark Mode
    • Web
      • Changing the Appearance of Controls
      • Control Hierarchy
      • Controllers
      • Dialog Boxes
      • Menus
        • Properties
        • Methods
        • Usage
      • Using Google Fonts
      • Web Pages
    • Windows UI guidelines
  • Web
  • Windows
  • Xojo Cloud
  • XojoScript

API

  • Android
  • Compiler directives
  • Console
  • Cryptography
  • Data types
  • Databases
  • Deprecated
  • Exceptions
  • Files
  • Graphics
  • Hardware
  • iOS
  • Language
  • macOS
  • Math
  • Mobile
  • Networking
  • OS
  • PDF
  • Printing
  • Text
  • User interface
  • Web
  • Windows
  • Xojo Cloud

RESOURCES

  • Deprecations
  • Learn object-oriented programming
  • Previous releases
  • Programming the Raspberry Pi with Xojo
  • Xojo 2025r1.1 Release Notes
  • Reporting bugs and making feature requests
  • Roadmap
  • System requirements
  • Extras
  • Updating older projects
  • Videos
  • XojoTalk podcast

ESPAÑOL

  • Guía Rápida
  • Iniciación
  • Tutorial

FINE PRINT

  • Copyrights and trademarks
  • End User License Agreement
Xojo
  • »
  • User interface »
  • Web »
  • Menus

Menus

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 for the complete list.

Properties

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

Value - The text that is displayed for the menu.

Methods

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

AddMenuItem - Adds a menu to a menu.

Usage

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")
menuItem1.AddMenuItem(subMenuItem1)

myMenu.AddMenuitem(menuItem1)
Me.ContextualMenu = myMenu

See also

WebMenuItem class; Toolbar topic

Previous Next

© Copyright 2025, Xojo, Inc.

Built with Sphinx using a theme provided by Read the Docs.

Have a suggestion about the docs? Let us know.

Docs for the Xojo programming language and IDE