Custom items can be added to a Context Menu.
TheView has a [ContextMenuView] property that can be configured in design time. Context menu items added here are visible when the user opens a context menu on the View, not on an object. These items are appended to the standard context menu.
TheView also has a [ContextMenuObjects] property that sets the default items for context menus opened on objects, not on TheView itself. These commands can be added to and overridden for individual objects using their [ContextMenu] properties.
Each context menu item is configured with an Event ID, which must be unique within a context menu. When a context menu item is clicked, an event handler on the View (EventContextMenuView or EventContextMenuObjects) or on individual objects (EventContextMenu) can perform an action based on the Event ID and the calling object.
The following example creates a small screen using a Slider object to set a "scale factor," which could be used in graphical applications or to otherwise scale data sets. A context menu item, "Reset" is used on the value a Text tool to reset the value to the default scale factor. A context menu item on TheView toggles the visibility of the scale controls.
To Configure a Context Menu
|
'(Declarations)
Dim defaultScaleFactor defaultScaleFactor = 0.1
'End of (Declarations) |
|
Sub txtScaleFactor_EventInitialize() Dim This : Set This = txtScaleFactor This.Text = defaultScaleFactor End Sub |
|
Sub SldScaleFactor_EventInitialize() Dim This : Set This = SldScaleFactor This.Value = defaultScaleFactor End Sub |
|
Sub SldScaleFactor_EventChange() Dim This : Set This = SldScaleFactor txtScaleFactor.Text = This.Value End Sub |
|
Sub txtScaleFactor_EventContextMenu(EventID) Dim This : Set This = txtScaleFactor If EventID = "RESET" Then This.Text = defaultScaleFactor SldScaleFactor.Value = defaultScaleFactor End If End Sub |
|
Sub TheView_EventContextMenuView(EventID) Dim This : Set This = TheView If EventID = "TOGGLESCALEVISIBILITY" Then If txtScaleFactor.Visible = 1 Then 'True txtScaleFactor.Visible = False SldScaleFactor.Visible = False Else txtScaleFactor.Visible = True SldScaleFactor.Visible = True End If End If End Sub |