Difference between revisions of "WebMenuItem"

From Xojo Documentation

 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{SupportedPlatforms | type = w}}
 
{{Desktop | link = [[MenuItem]]}}
 
 
{{ClassBox
 
{{ClassBox
 
| newinversion = 2011r2
 
| newinversion = 2011r2
| super = None
+
| super = Object
 
}}
 
}}
 
{{Description
 
{{Description
 
|text=An item in a [[WebToolbarMenu]] or a contextual menu used in a web page or web control. }}
 
|text=An item in a [[WebToolbarMenu]] or a contextual menu used in a web page or web control. }}
  
<dynamicTable id="Properties" class="propertyTable" title="Properties" columns="3">
+
<dynamicTable id="Constructors" class="methodTable" title="Constructors" columns="1">
{{Property | name=Count | type=Integer | platform= All | readonly=yes | newinversion=2011r2 | description= ( Integer) The number of children of the item. }}
+
{{Ctor | description=WebMenuItem()&#10;Creates a new empty WebMenuItem. }}
{{Property | name=Enabled | type=Boolean | platform= All | newinversion=2011r2 | description= ( Boolean) If true, the menu item is enabled. }}
+
{{Ctor | params=value As String | description=WebMenuItem(value As String )&#10; Creates a new WebMenuItem with the passed text.}}
{{Property | name=MenuID | type=String | platform= All | readonly=yes | newinversion=2011r2 | description= ( String) A unique ID given to the item. Cloning an item does not clone the menu id. }}
+
{{Ctor | params=value As String, Tag as Variant | description=WebMenuItem( value As String, Tag As Variant )&#10;Creates a new WebMenuItem with the passed text and tag.}}
{{Property | name=Text | type=String | platform= All | newinversion=2011r2 | description= ( String) The text of the menu item. Use '-' to create a separator. }}
+
</dynamicTable>
{{Property | name = Tag | type = Variant | readonly = no | newinversion = 2011r2 | description = (Variant)&nbsp;&nbsp;A hidden value associated with the menu item.}}
+
 
 +
<dynamicTable id="Enumerations" class="methodTable" title="Enumerations" columns="3">
 +
{{Enum | name=Positions | description=The various positions in which the contextual menu will be displayed relative to the control to which is is attached.}}
 +
{{Enum | name=Styles | description=Specifies the style of menu item (header, menuitem or separator).}}
 
</dynamicTable>
 
</dynamicTable>
  
 
<dynamicTable id="Methods" class="methodTable" title="Methods" columns="3">
 
<dynamicTable id="Methods" class="methodTable" title="Methods" columns="3">
{{Method | name=Append |  parameters=Item as WebMenuItem | newinversion=2011r2 | description=Append( Item as WebMenuItem )&#10;Appends the passed Item to the end of the menu. }}
+
{{Method | name=AddMenuItem |  parameters=value() As String | description=AddMenuItem(value() As String)&#10;Adds the passed array of values to the end of the menu. }}
{{Method | name=Child |  parameters=Text as String | returntype=WebMenuItem | newinversion=2011r2 | description=Child( Text as String ) as WebMenuItem&#10;Attempts to locate a child with the passed string. }}
+
{{Method | name=AddSeparator | description=AddSeparator&#10;Adds a separator line to the menu. }}
{{Method | name=Clone |  returntype=WebMenuItem | newinversion=2011r2 | description=Clone() as WebMenuItem&#10;Duplicates the menu and all its children. }}
+
{{Method | name=AddSeparatorAt | parameters=index As Integer | description=AddSeparatorAt(index As Integer)&#10;Adds a separator at the index passed.}}
{{Method | name=FindItem | parameters=MenuID as String |  newinversion=2011r2 | description=FindItem( MenuID as String)&#10; Recursively locates a menu item with the given menu id. }}
+
{{Method | name=AddMenuItemAt |  parameters=index As Integer, value As WebMenuItem | description=AddMenuItemAt(index As Integer, value As WebMenuItem )&#10;Adds the passed Item at the index position in the menu. }}
{{Method | name=Insert |  parameters=Index As Integer, Item as WebMenuItem | newinversion=2011r2 | description=Insert(Index As Integer, Item as WebMenuItem )&#10;Inserts the passed Item to the index position in the menu. }}
+
{{Method | name=RemoveMenuItemAt |  parameters=index As Integer |  description=RemoveMenuItemAt(index As Integer)&#10;RemoveMenuItemAt(Item as WebMenuItem)&#10;Removes the menu item at the index passed from the menu. }}
{{Method | name=Remove |  parameters=ZeroBasedIndex as Integer |  newinversion=2011r2 | description=Remove( ZeroBasedIndex as Integer)&#10;Remove( Item as WebMenuItem)&#10;Removes a menu item from the menu. }}
 
 
</dynamicTable>
 
</dynamicTable>
  
<dynamicTable id="Constructors" class="methodTable" title="Constructors" columns="1">
+
<dynamicTable id="Properties" class="propertyTable" title="Properties" columns="3">
{{Ctor | description=WebMenuItem()&#10;Creates a new empty WebMenuItem. }}
+
{{Property | name=Count | type=Integer | readonly=yes | description= (Integer) The number of children of the item. }}
{{Ctor | params=Text as String | description=WebMenuItem( Text as String )&#10; Creates a new WebMenuItem with the passed text. }}
+
{{Property | name=Enabled | type=Boolean | description= (Boolean) If true, the menu item is enabled. }}
{{Ctor | params=Text as String, Tag as Variant | description=WebMenuItem( Text as String, Tag as Variant )&#10;Creates a new WebMenuItem with the passed text and tag. }}
+
{{Property | name=Icon | type=Picture | description= (Picture) The icon to be displayed with the menu item. }}
 +
{{Property | name=LastAddedIndex | type=Integer | readonly=yes | description= (Integer) The index of the last menu item added to the menu.}}
 +
{{Property | name=Position | type=WebMenuItem.Positions | description= (String) The position in which the contextual menu will be displayed relative to the control to which is is attached. }}
 +
{{Property | name=Style | type=Styles | description= (Styles) Dictates the type of menuitem (header, menuitem or separator).}}
 +
{{Property | name=Value | type=String | description= ( String) The text of the menu item.}}
 +
{{Property | name = Tag | type=Variant | description = (Variant)&nbsp;&nbsp;A hidden value associated with the menu item.}}
 +
{{Property | name = TextColor | type=Color | description = (Variant)&nbsp;&nbsp;The color of the text in the menu item.}}
 
</dynamicTable>
 
</dynamicTable>
  
 
==Notes==
 
==Notes==
You can display a contextual menu in a web app by assigning the WebMenuItem to the [[WebControl.ContextualMenu]] property. When the user right+clicks on the control the contextual menu is displayed.
+
You can display a contextual menu in a web app by assigning the WebMenuItem to the [[WebUIControl.ContextualMenu|ContextualMenu]] property. When the user right+clicks on the control the contextual menu is displayed.
  
== Sample Code ==
+
==Sample Code==
 
To add a contextual menu to a Button, add a this code to the [[WebControl.Shown|Shown]] event handler:
 
To add a contextual menu to a Button, add a this code to the [[WebControl.Shown|Shown]] event handler:
 
<rbcode>
 
<rbcode>
 
Var menu As New WebMenuitem
 
Var menu As New WebMenuitem
 
+
menu.AddMenuItem("Frodo")
menu.Append(New WebMenuItem("Item 1"))
+
menu.AddMenuItem("Sam")
menu.Append(New WebMenuItem("Item 2"))
 
 
 
 
Me.ContextualMenu = menu
 
Me.ContextualMenu = menu
 
</rbcode>
 
</rbcode>
Line 47: Line 51:
 
Right-click on the button to show the menu.
 
Right-click on the button to show the menu.
  
To determine which menu was selected, use this code in the [[WebControl.ContextualMenuAction|ContextualMenuAction]] event handler:
+
To determine which menu was selected, use this code in the [[WebUIControl.ContextualMenuSelected|ContextualMenuSelected]] event handler:
 
<rbcode>
 
<rbcode>
Select Case Item.Text
+
Select Case Item.Value
Case "Item 1"
+
Case "Frodo"
   MessageBox("Item 1 selected.")
+
   MessageBox("You chose Frodo.")
Case "Item 2"
+
Case "Sam"
   MessageBox("Item 2 selected.")
+
   MessageBox("You chose Sam.")
 
End Select
 
End Select
 
</rbcode>
 
</rbcode>
Line 59: Line 63:
 
This code create a nested menu:
 
This code create a nested menu:
 
<rbcode>
 
<rbcode>
Var b As New WebMenuItem
+
Var myMenu As New WebMenuItem
  
Var m1 As New WebMenuItem("Parent")
+
Var menuItem1 As New WebMenuItem("Dark Wizards")
Var m2 As New WebMenuItem("Child")
+
Var subMenuItem1 As New WebMenuItem("Sauron")
m1.Append(m2)
+
menuItem1.AddMenuItem(subMenuItem1)
  
b.Append(m1)
+
myMenu.AddMenuitem(menuItem1)
Me.ContextualMenu = b
+
Me.ContextualMenu = myMenu
 
</rbcode>
 
</rbcode>
  

Latest revision as of 18:39, 3 November 2020

Class (inherits from Object)


New in 2011r2

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

Constructors

Constructor()


Constructor(value As String)


Constructor(value As String, Tag as Variant)


Enumerations
Positions Styles
Methods
AddMenuItem AddSeparator RemoveMenuItemAt
AddMenuItemAt AddSeparatorAt
Properties
Count fa-lock-32.png LastAddedIndex fa-lock-32.png Tag
Enabled Position TextColor
Icon Style Value

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.Value
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

See Also

WebToolbar, WebToolbarMenu, classes; UserGuide:Web Menus topic