Difference between revisions of "RectControl.ContextualMenuAction"

From Xojo Documentation

(Add explanation to notes about when to return true or false.)
 
(2 intermediate revisions by the same user not shown)
Line 14: Line 14:
 
==Notes==
 
==Notes==
 
This event gives you a chance to handle the menu selection by inspecting the menuitem's Text or Tag properties to see which item was selected. Use this in conjunction with ConstructContextualMenu if you have not specified the Action event or the Menu Handler for the items on the contextual menu. See the example of a contextual menu in the examples for the '''RectControl''' class.
 
This event gives you a chance to handle the menu selection by inspecting the menuitem's Text or Tag properties to see which item was selected. Use this in conjunction with ConstructContextualMenu if you have not specified the Action event or the Menu Handler for the items on the contextual menu. See the example of a contextual menu in the examples for the '''RectControl''' class.
 +
 +
[[Return]] [[True]] if this event has handled the item the user chose from the contextual menu. Returning [[False]] will cause the control's parent to execute its ContextualMenuAction event. This can be handy if you have the same contextual menu for several controls who share the same [[RectControl.Parent|Parent]] (several on the same window for example). By returning [[False]] you can handle them all in a single event.
  
 
== Sample Code ==
 
== Sample Code ==
Line 19: Line 21:
  
 
<rbcode>
 
<rbcode>
If hitItem <> Nil Then MsgBox(hitItem.Value)
+
If hitItem <> Nil Then MessageBox(hitItem.Value)
 
Return True
 
Return True
 
</rbcode>
 
</rbcode>
  
 
A more fine-grained event handler would compare the value of ''hitItem'' to all the expected values and take different actions depending on its value.
 
A more fine-grained event handler would compare the value of ''hitItem'' to all the expected values and take different actions depending on its value.

Latest revision as of 16:29, 10 April 2020

Event


RectControl.ContextualMenuAction(hitItem as MenuItem) As Boolean

New in 2005r1

Supported for all project types and targets.

Fires when a contextual menuitem hitItem was selected but the Action event and the MenuHandler for the menuitem did not handle the menu selection.

Notes

This event gives you a chance to handle the menu selection by inspecting the menuitem's Text or Tag properties to see which item was selected. Use this in conjunction with ConstructContextualMenu if you have not specified the Action event or the Menu Handler for the items on the contextual menu. See the example of a contextual menu in the examples for the RectControl class.

Return True if this event has handled the item the user chose from the contextual menu. Returning False will cause the control's parent to execute its ContextualMenuAction event. This can be handy if you have the same contextual menu for several controls who share the same Parent (several on the same window for example). By returning False you can handle them all in a single event.

Sample Code

This simple event handler displays the value of the selected menu item.

If hitItem <> Nil Then MessageBox(hitItem.Value)
Return True

A more fine-grained event handler would compare the value of hitItem to all the expected values and take different actions depending on its value.