Insert custom control in RichTextBox

8 posts, 0 answers
  1. Dj Prpa
    Dj Prpa avatar
    20 posts
    Member since:
    Aug 2012

    Posted 18 Jul 2010 Link to this post

    I would like to insert custom control into a RichTextBox control using code. How can I do it? Is it possible to have RichTextBox text areas as read only, but still to have ability to click on the custom control to launch RadWindow control?
  2. Vesko
    Admin
    Vesko avatar
    45 posts

    Posted 19 Jul 2010 Link to this post

    Hello Zoran Zigic,

    Thanks for your question!
    Yes - it is possible to have RadRichTextBox as readonly and still to have the ability to handle the click events of the inserted custom inline UI controls.

    The property which RadRichTextBox exposes for this purpose is named IsReadOnly. It should be set to true. What this property does is actually to prevent user from typing in the box, but it still allows selection, copy/paste, click, etc.

    To insert UIElement in the RadRichTextBox you can use the InlineUIContainer class. It has UiElement property and Width/Height properties that should be set explicitly.

    Here is a sample code for building a document using our API.
    this.editor.IsReadOnly = true;
    RadDocument doc = new RadDocument();
      
    Section section = new Section();
    doc.Sections.Add(section);
      
    Paragraph paragraph = new Paragraph();
    section.Paragraphs.Add(paragraph);
      
    Span span = new Span("Some Text before...");
    paragraph.Inlines.Add(span);
      
    Button button = new Button();
    button.Content = "Test Button";
    button.Width = 100;
    button.Height = 50;
      
    button.Click += 
        (s, a) => 
        {
            MessageBox.Show("Your button was just clicked!");
        };
      
    InlineUIContainer container = new InlineUIContainer();
    container.UiElement = button;
    container.Width = button.Width;
    container.Height = button.Height;
      
    paragraph.Inlines.Add(container);
      
    Span span2 = new Span("Some Text after...");
    paragraph.Inlines.Add(span2);
      
    editor.Document = doc;

    Please, let me know if this helps or are there any further questions.

    Greetings,
    Vesko
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Hürcan Bulut
    Hürcan Bulut avatar
    11 posts
    Member since:
    Nov 2009

    Posted 03 Aug 2010 Link to this post

    It seems that the InlineUIContainer doesn't exists anymore? Is that right? If yes, how can i else add a custom control to the RadRichTextBox?
    -- Solved, It was the wrong dll.
  4. Vesko
    Admin
    Vesko avatar
    45 posts

    Posted 05 Aug 2010 Link to this post

    Hello Hürcan Bulut,

    Actually InlineUIContainer class does exist and is located in Telerik.Windows.Documents.Model.InlineUIContainer. Its purpose is to insert UIElements in the document's tree. Just double-check your assembly references and aliases.

    All the best,
    Vesko
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Danny
    Danny avatar
    11 posts
    Member since:
    May 2018

    Posted 18 May 2018 in reply to Vesko Link to this post

    Hi,

    Any chance to have the same example/behavior in vb.net AND for WinForms?

    Thanks,

    Danny

  6. Boby
    Admin
    Boby avatar
    704 posts

    Posted 23 May 2018 Link to this post

    Hello Danny,

    You can check Add UI Element to an InlineUIContainer which is WinForms-specific, and has VB.NET code sample (in the tab next to the C# one).

    Regards,
    Boby
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  7. Danny
    Danny avatar
    11 posts
    Member since:
    May 2018

    Posted 24 May 2018 in reply to Boby Link to this post

    Thanks Bobby,

    I followed your suggestion and the attached code is working (good enough for this step). I have 2 more questions (and thank you in advance for any support):

    1. how to declare a Click event for the new inserted button/container

    2. why when I press Button2 twice or more times, there are no new lines added to the richtextbox except the first one? (for sure I'm not very familiar with the richtextbox control and in the same time I'm very new in programming...Sorry for tthat!)

    Danny

     

    Imports Telerik.WinControls
    Imports Telerik.WinControls.RichTextEditor.UI
    Imports Telerik.WinControls.UI
    Imports Telerik.WinForms.Documents.Commands.Styles
    Imports Telerik.WinForms.Documents.Model
    Public Class RadForm1
    Private Sub RadForm1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    End Sub
    Private Sub RadButton1_Click(sender As Object, e As EventArgs) Handles RadButton1.Click
    Me.RadRichTextEditor1.IsReadOnly = True
    Dim doc = New RadDocument()
    Dim Section = New Section()
    doc.Sections.Add(Section)
    Dim Paragraph = New Paragraph()
    Section.Blocks.Add(Paragraph)
    Dim Span = New Span("Some Text before...")
    Paragraph.Inlines.Add(Span)
    Dim Button As New RadButtonElement
    Button.Text = "Test Button"
    Dim Container As New InlineUIContainer()
    Dim radContainer As New RadElementUIContainer(Button)
    Container.UiElement = radContainer
    Container.Width = 200
    Container.Height = 15
    Paragraph.Inlines.Add(Container)
    Dim span2 = New Span("Some Text after..." & Environment.NewLine)
    Paragraph.Inlines.Add(span2)
    RadRichTextEditor1.Document = doc
    End Sub
    End Class

  8. Tanya
    Admin
    Tanya avatar
    823 posts

    Posted 29 May 2018 Link to this post

    Hi Danny,

    You will need to attach the handler in code, using the AddHandler method:
    AddHandler Button.Click, AddressOf MyButtonClickHandler

    As to the second question, I am not sure what logic is executed when clicking Button2 and what is the desired end result. Could you please share the code and elaborate more on what you would need to achieve and what is the current behavior?

    Regards,
    Tanya
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top