Displays a context menu at the given mouse location using the current ribbon theme.

Syntax

Send_Message(Ctrl, "OLE.ShowCommandContextMenu", Point, Commands, UserData)

Parameters

PropertyDescription
PointThe screen location to display the context menu. The format is X:@FM:Y or X,Y
CommandsThe @FM delimited list of ribbon commands to display. Blank fields create menu separators.
UserDataCustom information of your choosing that will be passed to the OnCommand event.

Remarks

The ShowCommandContextMenu method shows a Ribbon-themed context menu, complete with icons. You can display this context menu anywhere on the screen by passing X,Y coordinates. These coordinates are in screen coordinates, so passing "0,0" would display the context menu in the top left corner of the top left most screen.

The simplicity of this method is how it leverages Ribbon commands, which you likely already defined in Init. All you have to do is pass an @FM list of command IDs in the order you want them to appear. When the user clicks on one, it fires the OnCommand event. The ribbon control will not only use its current theme to draw the context menu, it'll even show the commands' icons, if they have one. Blank fields in the command list are interpreted as menu separators.

The UserData field is the data you want passed to the OnCommand event when it fires. It can be anything you want, but you must pass the parameter, even if you pass "".

Example

In the following example, we are adding a Find button to four different places: a group whose key is "EDITING", the Quick Access toolbar, the Tab Bar area, and to a Split Button's sub-menu dropdown. Note how we define the button's command the first time, then simply reference the command in all the other buttons. Thus, no matter which button the user clicks, the same event fires. All four buttons need to have a unique Key, even though they can share the same command.

// Show a themed context menu. Notice the blank entry between SAVE and COPY.
Commands     = ''
Commands<-1> = 'NEW'
Commands<-1> = 'OPEN'
Commands<-1> = 'SAVE'
Commands<-1> = ''
Commands<-1> = 'COPY'
Commands<-1> = 'CUT'
Commands<-1> = 'PASTE'
Send_Message(@Window:".OLE_RIBBON", "OLE.Show", "100,100", Commands, "")

See Also

OnCommand

  • No labels