7 Answers, 1 is accepted
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.
RadDocument doc =
Section section =
Paragraph paragraph =
Span span =
"Some Text before..."
Button button =
button.Width = 100;
button.Height = 50;
(s, a) =>
"Your button was just clicked!"
InlineUIContainer container =
container.UiElement = button;
container.Width = button.Width;
container.Height = button.Height;
Span span2 =
"Some Text after..."
editor.Document = doc;
Please, let me know if this helps or are there any further questions.
the Telerik team
InlineUIContainerdoesn'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.
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,
the Telerik team
Any chance to have the same example/behavior in vb.net AND for WinForms?
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).
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!)
Public Class RadForm1
Private Sub RadForm1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
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()
Dim Paragraph = New Paragraph()
Dim Span = New Span("Some Text before...")
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
Dim span2 = New Span("Some Text after..." & Environment.NewLine)
RadRichTextEditor1.Document = doc
You will need to attach the handler in code, using the AddHandler method:
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?