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

Set Font, Color

3 Answers 243 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 01 May 2012, 03:55 PM
I am setting the Font and Font color of a RadRichTextBox via the FontFamily and Foreground properties which are bound to properties on a ViewModel. This works quite well when I have the Text property bound to a property on a ViewModel, but when I instead use an HtmlDataProvider to provide the text to the RadRichTextBox, setting the Foreground and FontFamily properties no longer has any effect. 

Is there a way to set the Font and Font color via databinding to either the textbox or the dataprovider or will I have to change the Html to specify the font and color?

3 Answers, 1 is accepted

Sort by
0
Iva Toteva
Telerik team
answered on 03 May 2012, 06:13 PM
Hello Mike,

RadRichTextBox uses its default settings for FontFamily and FontSize when you open a new document or when you are showing plain text. If you open a .txt file, for example, or use TxtDataProvider to bind the content of the document, the default style settings will be used. However, if you import a rich text document, such as HTML, the font settings specified in the document will be used. If there are no explicit values for font size and font family, the default values of the format will be used. In the case of HTML that would be Times New Roman 11. This is the behavior by design, which ensures that the document will be shown as closest as possible to the way it would in a browser or Microsoft Word.

If you want to load a rich text document, but alter the way it looks, you can handle the SetupDocument event and change the document as you see fit. You can find more information and some examples of using this event in this article.

I hope this helps.

Regards,
Iva Toteva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Mike
Top achievements
Rank 1
answered on 03 May 2012, 06:40 PM
Iva,

Thanks for the information about the SetupDocument event; however, that will not provide exactly what I am looking for. I need to be able to change the font and color independently of loading the Html, that is, there are times when I will need to change the font after the control has loaded and the Html displayed.

Cheers,
Mike
0
Accepted
Iva Toteva
Telerik team
answered on 04 May 2012, 01:25 PM
Hello Mike,

You can manipulate the document using the API of RadRichTextBox in order to apply different formatting to the text. All methods and command of RadRichTextBox operate on the selection or (if there is no selection) to the place in the document where the caret is positioned. You can have buttons bound to the commands of the editor in the same way that we have done with RadRichTextBoxRibbonUI in the Telerik Editor demo from the Click-once demos. You can find more about the use of the commands in this article.

If you would like to perform changes to the document without providing UI for that, you can use the methods of RadRichTextBox such as ChangeFontSize, ChangeFontFamily, ChangeForeColor, etc. There are a few examples here. Due to the fact that the methods operate on the selection, you might also find this article helpful.

In case you need further assistance with a specific task, do not hesitate to contact us again.

Kind regards,
Iva Toteva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
RichTextBox
Asked by
Mike
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
Mike
Top achievements
Rank 1
Share this question
or