I have a small problem which I couldn't find any solution, even though it sounds so simple... The font in my RichTextEditor is too big (see the attached image for an example how it looks). I'm wondering how it's possible to change this font size to a smaller font. I tried several things such as
txtText.ChangeFontSize(4);
or
txtText.RichTextBoxElement.ChangeFontSize(4);
I couldn't find anything about it in the documentation. Is it even possible to change the displayed font size?
Best Regards,
Roman
6 Answers, 1 is accepted
Hello Roman,
ChangeFontSize method is the right way to change the font size of the RichTextEditor. I suppose that you have added some text in the document and then you use the ChangeFontSize method. If you do so and you already have a text added to the document I can suggest you to select it all before calling the ChangeFontSize method.
this.radRichTextEditor1.Document.Selection.SelectAll();
this.radRichTextEditor1.RichTextBoxElement.ChangeFontSize(8.5);
I hope this helps. Should you have any other questions do not hesitate to ask.
Regards,
Nadya
Progress Telerik
Thank you for the quick response.
Since I already tested the code in your answer I had another look at the rest of my code. I've seen that the Text is overwritten at some place (programmatically). This seems to reset the font style, is that correct? If I comment this piece of code where the text is overwritten, it works using your solution. So do I need to do call ChangeFontSize() everytime I overwrite the text programmatically?
Regards,
Roman
Hello Roman,
According to your description, it is not clear how exactly do you add the text programmatically. Could you please clarify that? I can suggest you using the span that represents an inline object which allows you to display formatted text.
Section section = new Section();
Paragraph paragraph = new Paragraph();
Span span = new Span("Span declared in code-behind");
paragraph.Inlines.Add(span);
section.Blocks.Add(paragraph);
this.radRichTextEditor1.Document.Sections.Add(section);
span.FontSize = 8.5;
I am looking forward to your reply.
Regards,
Nadya
Progress Telerik
I'm setting the text like this:
txtText.Text =
"Whatever"
;
Is the span recommended? Why not simply using the Text property?
Regards,
Roman
Hi Roman,
Setting the Text property will create a new RadDocument and this is why the styles are overridden. However, it is possible to set the default fonts. You can use the following properties for this:
radRichTextEditor1.RichTextBoxElement.DocumentInheritsDefaultStyleSettings = true;
radRichTextEditor1.RichTextBoxElement.Font = new Font("Segoe Script", 8, FontStyle.Regular);
I hope this helps. Should you have any other questions do not hesitate to ask.
Regards,
Dimitar
Progress Telerik
Thanks for the answer. This is good to know. Your solution works as well, thanks.
Best Regards,
Roman