Disable some context menus and menu items

2 posts, 1 answers
  1. Mihajlo
    Mihajlo avatar
    38 posts
    Member since:
    Aug 2018

    Posted 04 Oct 2018 Link to this post

    How do I disable context menus "EditHeader" and "EditFooter", so that they don't show up?

    How do I remove (rather than disable) context menu item "Hyperlink..."?

  2. Answer
    Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3469 posts

    Posted 05 Oct 2018 Link to this post

    Hello, Mihajlo, 

    The following code snippet demonstrates how you can control which items to be visible in the context menu that RadRichTextEditor shows and hide the redundant ones:

    public RadForm1()
    {
        InitializeComponent();
     
        Telerik.WinControls.RichTextEditor.UI.ContextMenu menu =
            this.radRichTextEditor1.RichTextBoxElement.ContextMenu as Telerik.WinControls.RichTextEditor.UI.ContextMenu;
        menu.ContentBuilder = new CustomContextMenuContentBuilder();
          
    }
     
    public class CustomContextMenuContentBuilder : Telerik.WinForms.RichTextEditor.RichTextBoxUI.Menus.ContextMenuContentBuilder
    {
        public override Telerik.WinForms.RichTextEditor.RichTextBoxUI.Menus.ContextMenuGroupCollection Construct()
        {
            Telerik.WinForms.RichTextEditor.RichTextBoxUI.Menus.ContextMenuGroupCollection collection = base.Construct();
     
            foreach (var item in collection)
            {
                Telerik.WinForms.RichTextEditor.RichTextBoxUI.Menus.ContextMenuGroup group = item as Telerik.WinForms.RichTextEditor.RichTextBoxUI.Menus.ContextMenuGroup;
                if (group!=null)
                {
                    foreach (var menuItem in group)
                    {
                        if (menuItem.Text.Contains("Hyperlink") )
                        {
                            menuItem.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
                        }
                    }
                }
            }
            return collection;
        }
     
        private void menuItem_Click(object sender, EventArgs e)
        {
            Console.WriteLine("Clicked");
        }
    }

    I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

    Regards,
    Dess
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top