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

Default Font & Size

6 Answers 703 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Nick Anderson
Top achievements
Rank 1
Nick Anderson asked on 11 Jan 2012, 08:10 PM

I am trying to default my FontSize to 8 and FontFamily to Arial, by doing:

richTextBox.FontFamily = New FontFamily("Arial")
richTextBox.FontSize = 10.67

When the richtextbox first loads, the comboxes are correct and the font is correct, however, when I save the html from the htmlformatprovider and load it back into a richtextbox, my font is now set as Verdana & 12. This is the html that was outputted:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled</title><style type="text/css">
p { text-indent: 0pt;padding: 0px 0px 0px 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 12px;margin-left: 0px;text-align: left;font-family: 'Verdana';font-style: Normal;font-weight: normal;font-size: 16px;color: #000000; } 
.defaultDocumentStyle { telerik-style-type: default;telerik-style-name: defaultDocumentStyle;font-family: 'Arial';font-style: Normal;font-weight: normal;font-size: 10.67px;margin-bottom: 0px; } 
.p_DEC438A7 { telerik-style-type: local; } 
.s_DEC438A7 { telerik-style-type: local; } 
</style></head><body><p class="p_DEC438A7"><span class="s_DEC438A7">Try again, do i get to save Arial 8?</span></p></body></html>

If I enter the control, change the font back to Arial and 8, it saves and reload correctly, this is the html that is now saved and works:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled</title><style type="text/css">
p { text-indent: 0pt;padding: 0px 0px 0px 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 12px;margin-left: 0px;text-align: left;font-family: 'Verdana';font-style: Normal;font-weight: normal;font-size: 16px;color: #000000; } 
.defaultDocumentStyle { telerik-style-type: default;telerik-style-name: defaultDocumentStyle;font-family: 'Arial';font-style: Normal;font-weight: normal;font-size: 10.67px;margin-bottom: 0px; } 
.p_DEE65F0 { telerik-style-type: local;margin-top: 0px;margin-right: 0px;margin-bottom: 12px;margin-left: 0px;text-align: left; } 
.s_8905ECE5 { telerik-style-type: local;font-family: 'Arial';font-style: Normal;font-weight: normal;font-size: 10.67px;color: #000000; } 
.s_9FFAD006 { telerik-style-type: local;font-family: 'Verdana';font-style: Normal;font-weight: normal;font-size: 16px;color: #000000; } 
</style></head><body><p class="p_DEE65F0"><span class="s_8905ECE5">Try again, do i get to save Arial 8?</span><span class="s_9FFAD006" /></p></body></html>

Everything used to work correctly before the Q3 SP1 version

How do I set the default font family and size correctly now? I wouldn't expect Verdana 12(16px) to be anywhere in the outputted html code.

6 Answers, 1 is accepted

Sort by
0
Accepted
Vasil
Telerik team
answered on 16 Jan 2012, 06:22 PM
Hi Nick,

Thank you for contacting Telerik Support.

With 2011 Q3 SP1 version RadRichTextBox introduces styles and the right way to set default font values is to use DocumentInheritsDefaultStyleSettings and set it to True. Unfortunately, there is a bug with export of default styles to HTML, so a work around has to be used.
The following code returns export settings to previous version (the way they worked before Q3 SP1) through setting DontExportStyles of StyleRepositoryExportMode. In this way fonts will be exported as local values.

HtmlFormatProvider fp = new HtmlFormatProvider();
fp.ExportSettings = new HtmlExportSettings() { StyleRepositoryExportMode = StyleRepositoryExportMode.DontExportStyles };
string html = fp.Export(this.radRichTextBox.Document);

Please, excuse us for the inconvenience. We have added Telerik  points to your account for reporting this issue. Don't hesitate to contact us if you have other questions.


Kind regards,
Vasil
the Telerik team

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

0
Nick Anderson
Top achievements
Rank 1
answered on 16 Jan 2012, 07:10 PM
Thank you, this work around does appear to work for me.
0
Sanket
Top achievements
Rank 1
answered on 29 Apr 2016, 05:54 PM
How can I dynamically change font size of selected text in telerik rad rich text box?

please help!
0
Tanya
Telerik team
answered on 03 May 2016, 03:13 PM
Hi Sanket,

You could modify the selected content inside RadRichTextBox using the methods of the same class or of RadDocumentEditor. The sample below shows how you could change the font size of the selected text to 10:
this.radRichTextBox.ChangeFontSize(Unit.PointToDip(10))

Please, note that the measurement unit in RadRichTextBox is Device-Independent Pixel and you may need to convert the value in order to get the desired result using the methods of the Unit class.

Hope this helps.

Regards,
Tanya
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Andi
Top achievements
Rank 1
commented on 12 Oct 2021, 11:14 AM

Hi there, 
how may I change the font and font size for the complete content of a RadRichTextBox?

TIA, Andi

Tanya
Telerik team
commented on 12 Oct 2021, 04:05 PM

Hi Andi,

You can select all the content and invoke the methods for modifying the desired properties:

radRichTextBox.Document.Selection.SelectAll();
radRichTextBox.ChangeFontFamily(new System.Windows.Media.FontFamily("Arial"));
radRichTextBox.ChangeFontSize(Unit.PointToDip(20));

0
Sanket
Top achievements
Rank 1
answered on 03 May 2016, 04:43 PM

Hi tanya thank you 

 

pls tell how can I convert content of rich text box into html format to send a mail?

style and other thing related to rich textbox ?

I went through demo was bit confusing pls help!

0
Tanya
Telerik team
answered on 05 May 2016, 03:34 PM
Hi Sanket,

You can use the Export() method of HtmlFormatProvider. More information on how to achieve this is available in the Import/Export article.

Regards,
Tanya
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
RichTextBox
Asked by
Nick Anderson
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Nick Anderson
Top achievements
Rank 1
Sanket
Top achievements
Rank 1
Tanya
Telerik team
Share this question
or