This is a migrated thread and some comments may be shown as answers.

Insert custom control in RichTextBox

7 Answers 375 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Dj Prpa
Top achievements
Rank 1
Dj Prpa asked on 19 Jul 2010, 03:48 AM
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?

7 Answers, 1 is accepted

Sort by
0
Vesko
Telerik team
answered on 19 Jul 2010, 03:40 PM
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
0
Hürcan Bulut
Top achievements
Rank 1
answered on 03 Aug 2010, 12:10 PM
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.
0
Vesko
Telerik team
answered on 05 Aug 2010, 03:43 PM
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
0
Danny
Top achievements
Rank 1
answered on 18 May 2018, 04:18 PM

Hi,

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

Thanks,

Danny

0
Boby
Telerik team
answered on 23 May 2018, 06:36 AM
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.
0
Danny
Top achievements
Rank 1
answered on 24 May 2018, 08:09 PM

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

0
Tanya
Telerik team
answered on 29 May 2018, 02:08 PM
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.
Tags
RichTextBox
Asked by
Dj Prpa
Top achievements
Rank 1
Answers by
Vesko
Telerik team
Hürcan Bulut
Top achievements
Rank 1
Danny
Top achievements
Rank 1
Boby
Telerik team
Tanya
Telerik team
Share this question
or