Class

WebMenuItem


Description

An item in a contextual menu used in a web page or web control.

Methods

Name

Parameters

Returns

Shared

AddMenuItem

value() As String

AddMenuItemAt

index As Integer, value As WebMenuItem

AddSeparator

AddSeparatorAt

index As Integer

Constructor

Constructor

value As String

Constructor

value As String, Tag As Variant

PopUp

PopUp

x As Integer, y As Integer

RemoveMenuItemAt

index As Integer

Item As WebMenuItem

Enumerations

WebMenuItem.Positions

Positions

The various positions in which the contextual menu will be displayed relative to the control to which is is attached.

Enum

Description

Default

Always on the side to which the user's OS writing direction is set. If left to right, the menu will appear on the left. If right to left, the menu will appear on the right.

Left

Always to the left of the control.

Right

Always to the right of the control.

WebMenuItem.Styles

Styles

Specifies the style of menu item (header, menuitem or separator).

Enum

Description

Header

The item text of the menu item appears but is not selectable.

Menu

A regular menu item.

Separator

A line that separates two other menu items.

Property descriptions


WebMenuItem.Count

Count As Integer

The number of children for the menu item.

This property is read-only.


WebMenuItem.Enabled

Enabled As Boolean

If True, the menu item is enabled.

Add a contextual menu to a Label with one of the menu items disabled. This code is in the Shown event handler of a WebLabel:

Var base As New WebMenuItem

Var loadMenu As New WebMenuItem("Load")
base.Append(loadMenu)

Var saveMenu As New WebMenuItem("Save")
saveMenu.Enabled = False
base.Append(saveMenu)

Me.ContextualMenu = base

WebMenuItem.Icon

Icon As WebPicture

A picture that is assigned to the WebMenuItem.

The following code is in the Opening event of a WebPage. The icon appears to the left of the menu item's text.

hobbitsMenu.Icon = Frodo

WebMenuItem.LastAddedIndex

LastAddedIndex As Integer

The index of the last menu item added to the WebMenuItem.

This property is read-only.


WebMenuItem.Position

Position As Positions

The position of the WebMenuItem relative to the control to which it is attached.


WebMenuItem.Style

Style As Styles

The style or type of the menu item.

The options are Header, Menu and Separator.

Create a new menu item and set it to be a header:

Var m As New WebMenuItem
m.Text = "Customers"
m.Style = WebMenuItem.Styles.Header

WebMenuItem.Tag

Tag As Variant

A hidden value associated with the menu item.

The tag is accessible via code when the user chooses the menu item but, unlike the Text property, is not displayed in the menu. It works like the RowTag property of a PopupMenu control.

The Tag is a variant so it can contain any value, including class references.

This code displays a menu when you right-click on a Label. This code is in the Shown event handler of a WebLabel:

Var file As New WebFile
file.MimeType = "text/plain"
file.ForceDownload = True ' If False, the browser may try to display the file instead of download it
file.FileName = "TextFile.txt"
file.Data = "Hello, world!"

Var base As New WebMenuItem

Var downloadMenu As New WebMenuItem("Download")
downloadMenu.Tag = file ' The file to download
base.AddMenuItem(downloadMenu)

Me.ContextualMenu = base

In the ContextualMenuAction event handler of the WebLabel, you can then use the tag to download the previously created file:

If Item.Text = "Download" Then
  Var file As WebFile = Item.Tag
  System.GotoURL(file.URL)
End If

WebMenuItem.Text

Text As String

The text displayed.

Set the text of the menu item to "Hobbiton":

myMenu.Text = "Hobbiton"

WebMenuItem.TextColor

TextColor As ColorGroup

Gets or sets the color of the text of the WebMenuItem. The default value is black.

The following example sets the TextColor.

Me.TextColor = Color.Blue

Method descriptions


WebMenuItem.AddMenuItem

AddMenuItem(value() As String)

Adds the rows in the array passed as menu items to the WebMenuItem.

The value passed can also be a ParamArray.


WebMenuItem.AddMenuItemAt

AddMenuItemAt(index As Integer, value As WebMenuItem)

Adds the value passed as a new menu item at the index passed.


WebMenuItem.AddSeparator

AddSeparator

Adds a separator to the menu item.

Create a new web menu item and add a separator to it:

Var m As New WebMenuItem
m.AddSeparator

WebMenuItem.AddSeparatorAt

AddSeparatorAt(index As Integer)

Adds a separator to the menu item at the index passed.

Add a separator at index 12 of the editMenu object:

editMenu.AddSeparatorAt(12)

WebMenuItem.Constructor

Constructor

Note

Constructors are special methods called when you create an object with the New keyword and pass in the parameters above.

Creates an empty WebMenuItem.


WebMenuItem.Constructor

Constructor(value As String)

Note

Constructors are special methods called when you create an object with the New keyword and pass in the parameters above.

Creates a new WebMenuItem assigning the value passed to the Text property.


WebMenuItem.Constructor

Constructor(value As String, Tag as Variant)

Note

Constructors are special methods called when you create an object with the New keyword and pass in the parameters above.

Creates a new WebMenuItem assigning the value parameter passed to the Text property and the optional Tag to the Tag property.


WebMenuItem.PopUp

PopUp

Displays the contextual menu at the mouse position.


PopUp(x As Integer, y As Integer)

Displays the contextual menu at the coordinates passed.


WebMenuItem.RemoveMenuItemAt

RemoveMenuItemAt(index As Integer)

Removes the menu item at the index passed.


WebMenuItem.RemoveMenuItemAt

RemoveMenuItemAt(Item As WebMenuItem)

Removes the menu item at the index passed.

Notes

You can display a contextual menu in a web app by assigning the WebMenuItem to the ContextualMenu property. When the user right+clicks on the control the contextual menu is displayed.

Sample code

To add a contextual menu to a Button, add a this code to the Shown event handler:

Var menu As New WebMenuitem
menu.AddMenuItem("Frodo")
menu.AddMenuItem("Sam")
Me.ContextualMenu = menu

Right-click on the button to show the menu.

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

Select Case Item.Text
Case "Frodo"
  MessageBox("You chose Frodo.")
Case "Sam"
  MessageBox("You chose Sam.")
End Select

This code create a nested menu:

Var myMenu As New WebMenuItem

Var menuItem1 As New WebMenuItem("Dark Wizards")
Var subMenuItem1 As New WebMenuItem("Sauron")
menuItem1.AddMenuItem(subMenuItem1)

myMenu.AddMenuitem(menuItem1)
Me.ContextualMenu = myMenu

Compatibility

Web projects on all supported operating systems.

See also

Object parent class; WebToolbar class; Menus topic