Default Font & Size

7 posts, 1 answers
  1. Nick Anderson
    Nick Anderson avatar
    40 posts
    Member since:
    May 2009

    Posted 11 Jan 2012 Link to this post

    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.
  2. Answer
    Vasil
    Admin
    Vasil avatar
    124 posts

    Posted 16 Jan 2012 Link to this post

    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 >>

  3. UI for WPF is Visual Studio 2017 Ready
  4. Nick Anderson
    Nick Anderson avatar
    40 posts
    Member since:
    May 2009

    Posted 16 Jan 2012 Link to this post

    Thank you, this work around does appear to work for me.
  5. Sanket
    Sanket avatar
    6 posts
    Member since:
    Jan 2016

    Posted 29 Apr in reply to Nick Anderson Link to this post

    How can I dynamically change font size of selected text in telerik rad rich text box?

    please help!
  6. Tanya
    Admin
    Tanya avatar
    405 posts

    Posted 03 May Link to this post

    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.
  7. Sanket
    Sanket avatar
    6 posts
    Member since:
    Jan 2016

    Posted 03 May in reply to Tanya Link to this post

    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!

  8. Tanya
    Admin
    Tanya avatar
    405 posts

    Posted 05 May Link to this post

    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.
Back to Top
UI for WPF is Visual Studio 2017 Ready