ContextMenu Property
Description
This is the context menu that is displayed when a user right-clicks on a control during CommandBar customization.
Property Type
Read-only property
Syntax (Visual Basic)
Public Property ContextMenu() As [CommandBar](XtremeCommandBars~CommandBar.md)
Remarks
- Only controls that you have added to the context menu will trigger the Execute event. Built-in controls that are displayed in the context menu will not trigger the Execute event.
- The CustomizedControl property points to the control that the user is currently customizing.
- The CustomizedControl property always points to the control that the user is customizing and is updated each time the user clicks on a control. This is the control that has a black frame around it during CommandBar customization. You must use the CustomizedControl to make changes to the "original" control the user is modifying. Any changes made to the CustomizedControl will be applied to the original control. This is not necessary when using the "built-in" controls of the context menu.
The picture below displays the ContextMenu shown when the user right-clicks on a control during customization. These are the typical commands that are included with the ContextMenu's collection of controls. You can add your own custom controls and remove any of the "built-in" commands. Notice the Save button has a black focus rectangle around it. The control that has the black focus rectangle is copied into the CustomizedControl property.

Example
Adding Custom Controls to the Context Menu (Visual Basic)
This sample illustrates how to add controls to the context menu that is displayed when a user right-clicks on a control during CommandBar customization.
'==========================================================================================================
' Customization Event
'==========================================================================================================
' Custom commands are added to the context menu in the Customization event. This event is
' fired each time the Customization dialog is displayed.
Private Sub CommandBars_Customization(ByVal Options As XtremeCommandBars.ICustomizeOptions)
'==========================================================================================================
' Add custom controls to the context menu that is displayed when a control is
' right-clicked during customization
'==========================================================================================================
' Add an edit control to the context menu that is displayed when the user right-clicks a
' control during customization. Passing a 4 in as the "Before" parameter will insert this
' edit control as the fourth control in the context menu. The control will have a caption
' label of "Parameter." When this control is clicked, the execute event is fired and
' the control will have an Id of ID_EDIT_PARAM. See description of CustomizeOptions.ContextMenu
' and CommandBars.CustomizedControl for more information on adding control to the context menu.
Options.ContextMenu.Controls.Add xtpControlEdit, ID_EDIT_PARAM, "Parameter", 4
End Sub
'==========================================================================================================
' Execute Event
'==========================================================================================================
' The Execute event is triggered when the user clicks on a control added to the context menu
' by the developer. The CommandBars.CustomizedControl property points to the control that the
' user is currently customizing. This is the control that has the black frame placed around it
' during customization. The CommandBars.CustomizedControl property is how you know which control
' the user is customizing. When you make changes to the CommandBars.CustomizedControl, all changes
' will automatically be applied to the "original" control the user is customizing.
Private Sub CommandBars_Execute(ByVal Control As XtremeCommandBars.ICommandBarControl)
On Error Resume Next
Select Case Control.Id
' Id of the custom control added to the context menu, this was added
' during the Customization event. When the user hits the Enter key
' after typing text into the edit control added, the execute event is
' triggered and the control property contains a reference to the
' edit control.
Case ID_EDIT_PARAM:
Dim ControlEdit As CommandBarEdit
' Control is currently pointing to the custom control added
' to the context menu.
Set ControlEdit = Control
' Update the "Parameter" property of the control to hold the text
' stored in the edit box. The CustomizedControl property is a pointer
' to the control that the user is customizing. So any changes made
' to the CustomizedControl will be applied to the control the user is
' currently customizing.
CommandBars.CustomizedControl.Parameter = ControlEdit.Text
End Select
End Sub
See Also
Copyright (c) 1998-2024 Codejock Technologies. All rights reserved.