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.
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
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.
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
Hi,
Any chance to have the same example/behavior in vb.net AND for WinForms?
Thanks,
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
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
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