Nevron Open Vision Documentation
Rich Text Editor / Commanding / Context Menu
In This Topic
    Context Menu
    In This Topic

    The NOV Rich Text the context menu consists of a mini toolbar, which shows quick formatting commands and a context menu with element specific items. The context menu is shown when the user right-clicks somewhere in the rich text view.

    NOV Text Editor lets you fully customize the context menu. It is created by the rich text context menu builder assigned to the ContextMenuBuilder property of the rich text view's selection. This builder contains a list of context menu group builders, each of which is associated with a specific text element and builds the part of the context menu related to this element.

     Hiding the Context Menu

    To hide the rich text context menu mini toolbar set the ShowMiniToolbar property of the context menu builder to false.

    Hiding the mini toolbar
    Copy Code
    richTextView.ContextMenuBuilder.ShowMiniToolbar = false;

    To hide the context menu items, you should clear all groups of the context menu builder:

    Hiding the context menu items
    Copy Code

    To hide the whole context menu, use both lines of code shown above.

     Modifying Group Builders List

    You can easily add and remove context menu groups from the builder by using its AddGroup, InsertGroup and RemoveGroup methods. The names of the predefined groups are available as constants in the NRichTextMenuGroup. The following code fragment demonstrates how to remove a context menu group and add a custom one to the rich text context menu builder:

    Add and remove group builders
    Copy Code
    // Get the context menu builder
    NRichTextContextMenuBuilder builder = m_RichText.Selection.ContextMenuBuilder;
    // Remove the common menu group, which contains commands such as Cut, Copy, Paste, etc.
    // Add the custom context menu group
    builder.AddGroup(new CustomMenuGroup());
     Custom Context Menu Groups

    To create a custom context menu group, you should create a class, which inherits NRichTextMenuGroup. In your custom class you should first override the AppliesTo method in order to indicate to which text elements your custom menu group applies. Then you can override the AppendActionsTo and/or the AppendPropertiesTo method to append the actions/properties of the custom context menu group to the menu currently being constructed.

    The following example demonstrates how to create a custom rich text context menu group:

    Custom rich text context menu group
    Copy Code
    public class CustomMenuGroup : NRichTextMenuGroup
        public CustomMenuGroup()
            : base("Custom")
        public override bool AppliesTo(NTextElement textElement)
            return true;
        public override void AppendActionsTo(NMenu menu, NTextElement textElement)
            // Add the "Copy" command
            menu.Items.Add(CreateMenuItem(Nevron.Nov.Presentation.NResources.Image_Edit_Copy_png, NRichTextView.CopyCommand));
           // Add the custom command
           menu.Items.Add(CreateMenuItem(NResources.Image_Ribbon_16x16_smiley_png, CustomCommand));
    See Also