Customize RichTextEditor Controls

2 posts, 0 answers
  1. Roger
    Roger avatar
    1 posts
    Member since:
    Sep 2016

    Posted 18 Sep Link to this post

    hi

    i use rich text editor with ribbon ui and have several questions

    1. i have a rich text editors with ribbon ui. how can customize the ribbon groups that show my desired element. for example i dont want bullets group.

    2. in code block example in win forms rich text editor, the RadItem is create and added to home tab but there is no click event that show the code block is executed.

    3. i have an executable file that i want execute in insert tab. how can i do that?

    4.how can i subscribe a method to execute when user click symbol instead of default action.

    thanks you

  2. Hristo
    Admin
    Hristo avatar
    716 posts

    Posted 21 Sep Link to this post

    Hi Roger,

    Thank you for writing.

    RichTextEditorRibbonBar can be accessed at run-time and the existing elements customized or new ones added. It is also possible to inherit the control and extend the existing functionality, all of its members are protected so they could be manipulated in the inherited control. The example below demonstrates how you can programmatically customize the existing ribbon bar: 
    public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
     
                this.Load += Form1_Load;
            }
     
            private void Form1_Load(object sender, EventArgs e)
            {
                this.HideCommandGroups();
                this.RemoveIndentButton();
                this.CreateCommandTab();
                this.AddNewDropDownElement();
            }
     
            private void AddNewDropDownElement()
            {
                foreach (RichTextEditorRibbonTab commandTab in this.richTextEditorRibbonBar1.CommandTabs)
                {
                    if (commandTab.Text == "Home")
                    {
                        foreach (RadRibbonBarGroup group in commandTab.Items)
                        {
                            if (group.Text == "Font")
                            {
                                var g = new RadRibbonBarGroup();
                                RadDropDownListElement el = new RadDropDownListElement();
                                el.Items.Add("Item 1");
                                el.Items.Add("Item 2");
                                el.Items.Add("Item 3");
                                el.EditableElement.MinSize = new Size(50, 0);
     
                                group.Items[1].Children[1].Children.Add(el);
                            }
                        }
                    }
                }
            }
           
            private void HideCommandGroups()
            {
                foreach (RichTextEditorRibbonTab commandTab in this.richTextEditorRibbonBar1.CommandTabs)
                {
                    if (commandTab.Text != "Home")
                    {
                        commandTab.Visibility = ElementVisibility.Collapsed;
                    }
                    else
                    {
                        foreach (RadRibbonBarGroup group in commandTab.Items)
                        {
                            if (!(group.Text == "Font" || group.Text == "Paragraph"))
                            {
                                group.Visibility = ElementVisibility.Collapsed;
                            }
                        }
                    }
                }
            }
     
            private void RemoveIndentButton()
            {
                foreach (RichTextEditorRibbonTab commandTab in this.richTextEditorRibbonBar1.CommandTabs)
                {
                    if (commandTab.Text == "Home")
                    {
                        foreach (RadRibbonBarGroup group in commandTab.Items)
                        {
                            if (group.Text == "Font")
                            {
                                group.Items[1].Children[1].Children[1].Children[1].Children[1].Visibility = ElementVisibility.Collapsed;
                            }
                        }
                    }
                }
            }
     
            private void CreateCommandTab()
            {
                RichTextEditorRibbonTab newTab = new RichTextEditorRibbonTab();
                newTab.Text = "My Command Tab";
                RadRibbonBarGroup newGroup = new RadRibbonBarGroup();
                newGroup.Text = "My Group";
     
                newTab.Items.Add(newGroup);
                this.richTextEditorRibbonBar1.CommandTabs.Add(newTab);
            }
        }

    Regarding your second question, the code button is added from the ribbon and on click it simply executes the ShowInsertDateTimeDialogCommand. Additional information on the code block functionality is available here: http://docs.telerik.com/devtools/winforms/richtexteditor/features/code-block.

    Considering your third question, you can either inherit the ribbon or use the approach above to add an additional element in the Insert tab. Then you can handle the Click event and do what is necessary.

    When you click an element in RichTextEditorRibbonBar a command is being initialized and then executed. You can plug into that process and handle the CommandExecuting event of the editor. If necessary you can cancel the command or simply also call you method.

    I hope this information was useful. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms. For more information check out this blog post and share your thoughts.
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top