Changing Default Font and Size

31 posts, 1 answers
  1. Troy Clemons
    Troy Clemons avatar
    69 posts
    Member since:
    Apr 2010

    Posted 14 Aug 2015 Link to this post

    I am needing that every document (text file) is converted to the same Font(Consolas) and Size(10).

     I have tried 

    Public Sub SetDefaultFontPropertiesToEditor(ByVal editor As RadRichTextEditor)
     
    editor.RichTextBoxElement.ChangeFontFamily(New Telerik.WinControls.RichTextEditor.UI.FontFamily("Consolas"))
     
    editor.RichTextBoxElement.ChangeFontSize(Unit.PointToDip(10))
     
    editor.DocumentInheritsDefaultStyleSettings = True
     
     End Sub

    Which changes the Font and Size drop downs but not the document.

    any thoughts


     
  2. Troy Clemons
    Troy Clemons avatar
    69 posts
    Member since:
    Apr 2010

    Posted 17 Aug 2015 in reply to Troy Clemons Link to this post

    I got it figured out.

    Dim editor As New RadDocumentEditor(document)
            document.Selection.SelectAll()
            editor.ChangeFontSize(10)
            editor.ChangeFontFamily(New Telerik.WinControls.RichTextEditor.UI.FontFamily("Consolas"))
            Dim marg As New Telerik.WinForms.Documents.Layout.Padding(25, 25, 25, 25)
            editor.ChangeSectionActualPageMargin(marg)

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Dimitar
    Admin
    Dimitar avatar
    1408 posts

    Posted 17 Aug 2015 Link to this post

    Hello Troy,

    Your solution is correct. If the document already has content you should select it first.

    Please let me know if there is something else I can help you with. 
     
    Regards,
    Dimitar
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  5. Troy Clemons
    Troy Clemons avatar
    69 posts
    Member since:
    Apr 2010

    Posted 17 Aug 2015 in reply to Dimitar Link to this post

    if I add text to the document, how do I change the color of the added font.

     I am trying

    Dim documentEditor As New RadDocumentEditor(Me.RadRichTextEditor1.Document)
    documentEditor.ChangeForeColor(Color.Red)
    documentEditor.Insert (str)

    but this does not work. what am I missing
  6. Dimitar
    Admin
    Dimitar avatar
    1408 posts

    Posted 18 Aug 2015 Link to this post

    Hi Troy,

    Thank you for writing back.

    Your approach is correct, but you should set the color like this:
    Dim documentEditor As New RadDocumentEditor(Me.radRichTextEditor1.Document)
    documentEditor.ChangeForeColor(Telerik.WinControls.RichTextEditor.UI.Colors.Red)
    documentEditor.Insert("test")

    Let me know if you have additional questions.
     
    Regards,
    Dimitar
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  7. Troy Clemons
    Troy Clemons avatar
    69 posts
    Member since:
    Apr 2010

    Posted 18 Aug 2015 in reply to Dimitar Link to this post

    yes that changed the default editors color to red, but I need the inserted text to be red after insert.
  8. Answer
    Dimitar
    Admin
    Dimitar avatar
    1408 posts

    Posted 19 Aug 2015 Link to this post

    Hi Troy,

    Thank you for writing back.

    You can insert a span instead of just text fragment:
    Dim documentEditor As New RadDocumentEditor(Me.radRichTextEditor1.Document)
      
    Dim span As New Span("Span declared in code-behind")
    span.ForeColor = Colors.Red
    documentEditor.InsertInline(span)

    Please let me know if there is something else I can help you with. 
     
    Regards,
    Dimitar
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  9. Mahmoud
    Mahmoud avatar
    16 posts
    Member since:
    Jul 2013

    Posted 26 Aug 2015 Link to this post

    radRichTextEditor1 how to make less spacing winforms
  10. Troy Clemons
    Troy Clemons avatar
    69 posts
    Member since:
    Apr 2010

    Posted 26 Aug 2015 Link to this post

    Funny you should ask. I just did this on my side.

     

    Dim editor As New RadDocumentEditor(document)
            document.Selection.SelectAll()
            editor.ChangeFontSize(10)
            editor.ChangeFontFamily(New Telerik.WinControls.RichTextEditor.UI.FontFamily("Consolas"))
            Dim marg As New Telerik.WinForms.Documents.Layout.Padding(15, 15, 15, 15)
            editor.ChangeSectionActualPageMargin(marg)
            editor.ChangeParagraphSpacingAfter(0.0)
            editor.ChangeParagraphSpacingBefore(0.0)

    Note the last 2 editor lines for spacing
  11. Mahmoud
    Mahmoud avatar
    16 posts
    Member since:
    Jul 2013

    Posted 26 Aug 2015 in reply to Troy Clemons Link to this post

    sorry i need this c# and where put this code
  12. Troy Clemons
    Troy Clemons avatar
    69 posts
    Member since:
    Apr 2010

    Posted 26 Aug 2015 Link to this post

    I am using a function to create the RadDocument, hope this helps

    private void BatchProof_Load(object sender, EventArgs e)
    {
        RadRichTextEditor1.Document = ImportFile(_ContractRef);
    }
     
     
    public RadDocument ImportFile(string contract)
    {
        RadDocument document = null;
        IDocumentFormatProvider provider = new TxtFormatProvider();
     
        using (IO.Stream stream = IO.File.Open("your file your reading", IO.FileMode.Open)) {
            document = provider.Import(stream);
        }
        RadDocumentEditor editor = new RadDocumentEditor(document);
        document.Selection.SelectAll();
        editor.ChangeFontSize(10);
        editor.ChangeFontFamily(new Telerik.WinControls.RichTextEditor.UI.FontFamily("Consolas"));
        Telerik.WinForms.Documents.Layout.Padding marg = new Telerik.WinForms.Documents.Layout.Padding(15, 15, 15, 15);
        editor.ChangeSectionActualPageMargin(marg);
        editor.ChangeParagraphSpacingAfter(0.0);
        editor.ChangeParagraphSpacingBefore(0.0);
     
        RadRichTextEditor1.CurrentEditingStyle.SetPropertyValue(Span.ForeColorProperty, Colors.Red);
     
        return document;
    }
     

     

  13. Mahmoud
    Mahmoud avatar
    16 posts
    Member since:
    Jul 2013

    Posted 26 Aug 2015 in reply to Troy Clemons Link to this post

    sorry sir 

    plz find attach

    what is the parameter importfile ?

  14. Troy Clemons
    Troy Clemons avatar
    69 posts
    Member since:
    Apr 2010

    Posted 26 Aug 2015 in reply to Mahmoud Link to this post

    Use This

    private void BatchProof_Load(object sender, EventArgs e)
     
    {
     
        RadRichTextEditor1.Document = ImportFile();
     
    }
      
     
    public RadDocument ImportFile()
     
    {
     
        RadDocument document = null;
     
        IDocumentFormatProvider provider = new TxtFormatProvider();
     
     
        using (IO.Stream stream = IO.File.Open("c:\\123.doc", IO.FileMode.Open)) {
     
            document = provider.Import(stream);
     
        }
     
        RadDocumentEditor editor = new RadDocumentEditor(document);
     
        document.Selection.SelectAll();
     
        editor.ChangeFontSize(10);
     
        editor.ChangeFontFamily(new Telerik.WinControls.RichTextEditor.UI.FontFamily("Consolas"));
     
        Telerik.WinForms.Documents.Layout.Padding marg = new Telerik.WinForms.Documents.Layout.Padding(15, 15, 15, 15);
     
        editor.ChangeSectionActualPageMargin(marg);
     
        editor.ChangeParagraphSpacingAfter(0.0);
     
        editor.ChangeParagraphSpacingBefore(0.0);
     
      
     
        RadRichTextEditor1.CurrentEditingStyle.SetPropertyValue(Span.ForeColorProperty, Colors.Red);
     
      
     
        return document;
     
    }

  15. Mahmoud
    Mahmoud avatar
    16 posts
    Member since:
    Jul 2013

    Posted 26 Aug 2015 in reply to Troy Clemons Link to this post

    i have other error plz find attached
  16. Troy Clemons
    Troy Clemons avatar
    69 posts
    Member since:
    Apr 2010

    Posted 26 Aug 2015 Link to this post

    If you are working on windows 7 or higher, the root drive ("C:\") is not a great place to access files from as the security is set real high.

     

    I suggest using "C:\Temp\123.docx" and make sure you can read and write to that folder

  17. Mahmoud
    Mahmoud avatar
    16 posts
    Member since:
    Jul 2013

    Posted 26 Aug 2015 in reply to Troy Clemons Link to this post

    see i am custom the code put when run see attache

    -----------------code

      public RadDocument ImportFile()
            {

                RadDocument document = null;

                IDocumentFormatProvider provider = new TxtFormatProvider();
                //
                System.Windows.Forms.OpenFileDialog openDialog = new System.Windows.Forms.OpenFileDialog();
                openDialog.Filter = "Documents|*.docx";
                openDialog.Multiselect = false;
                DialogResult dialogResult = openDialog.ShowDialog();
                //
                if (dialogResult == System.Windows.Forms.DialogResult.OK)
                {
                    using (Stream stream = openDialog.OpenFile())
                    {
                        document = provider.Import(stream);
                    }
                }
                    //using (System.IO.Stream stream = System.IO.File.Open("c:\\123.docx", System.IO.FileMode.Open))
                    //{

                    //    document = provider.Import(stream);

                    //}

                    RadDocumentEditor editor = new RadDocumentEditor(document);

                    document.Selection.SelectAll();

                    editor.ChangeFontSize(10);

                    editor.ChangeFontFamily(new Telerik.WinControls.RichTextEditor.UI.FontFamily("Consolas"));

                    Telerik.WinForms.Documents.Layout.Padding marg = new Telerik.WinForms.Documents.Layout.Padding(15, 15, 15, 15);

                    editor.ChangeSectionActualPageMargin(marg);

                    editor.ChangeParagraphSpacingAfter(0.0);

                    editor.ChangeParagraphSpacingBefore(0.0);



                    radRichTextEditor1.CurrentEditingStyle.SetPropertyValue(Span.ForeColorProperty, Colors.Red);



                    return document;
               
            }​

  18. Mahmoud
    Mahmoud avatar
    16 posts
    Member since:
    Jul 2013

    Posted 27 Aug 2015 Link to this post

    hello

    when use font name " Al-mohanad" in radrichtexteditor" cannot and showing the words 

    plz find attached   

  19. Mahmoud
    Mahmoud avatar
    16 posts
    Member since:
    Jul 2013

    Posted 27 Aug 2015 Link to this post

    hello

    how remove data or clear radRichTextEditor1 in c# 

  20. Mahmoud
    Mahmoud avatar
    16 posts
    Member since:
    Jul 2013

    Posted 27 Aug 2015 Link to this post

    how to remove text radRichTextEditor1. in c# 
  21. Troy Clemons
    Troy Clemons avatar
    69 posts
    Member since:
    Apr 2010

    Posted 27 Aug 2015 Link to this post

    have you tried RadRichTextEditor1.Document =  NULL;
  22. Mahmoud
    Mahmoud avatar
    16 posts
    Member since:
    Jul 2013

    Posted 27 Aug 2015 Link to this post

    not working there exception "Object reference not set to an instance of an object."'.....??? 
  23. Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    711 posts

    Posted 31 Aug 2015 Link to this post

    Hello guys,

    Thank you for writing.

    @Mahmoud
    I am sending you attached a sample project in which I am importing a .docx file into RadRichTextEditor. Basically, I have followed the example as demonstrated here: Import/Export. You should also make sure that the file you are trying to read is available, not locked and you have the required permissions to access it. In my project, I have also demonstrated how the content can be cleared and how the spacing can be decreased. For detailed information and examples of the available features in RadRichTextEditor please refer to the following section of our documentation: Features.

    Considering your request, regarding the Al-mohanad font, please check the following forum thread as the same matter has also been discussed there: http://www.telerik.com/forums/changing-copied-arabic-text-font-in-document-richtexteditor.

    My example is in C#, in case you need conversion between VB and C# and vice versa, please note that we have a free online tool available here: http://converter.telerik.com/.

    I hope this helps. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  24. Myoungsu
    Myoungsu avatar
    7 posts
    Member since:
    Jul 2015

    Posted 17 Sep 2015 Link to this post

    Where is RadDocumentEditor class? I can't find it.

    And I don't want to RadDocumentEditor class. I just want to change default value of RadRichTextEdtitor.

    How to do it?

    Inspite of change font property of RadRichTextEditor, font is not change font is like below

    Font
        Font Family: Verdana     -> Want to change Arial
        Font Style: Normal
        Font Weight: Normal
        Font Size: 12                   -> Want to change 10
    Paragraph
        Spacing After: 12
        Line Spacing: 1.15            -> Want to change 0.5
    Style
       Type: Default

  25. Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    711 posts

    Posted 17 Sep 2015 Link to this post

    Hi Myoungsu,

    Thank you for writing.

    RadDocumentEditor class is part of the Telerik.WinForms.Documents.Model namespace and is located in the Telerik.WinControls.RichTextEditor.dll assembly.

    Considering your task, you can achieve it the following way: 
    private void SetDefaultFontPropertiesToEditor(RadRichTextEditor editor)
    {
        editor.Document.Selection.SelectAll();
        editor.RichTextBoxElement.ChangeFontFamily(new Telerik.WinControls.RichTextEditor.UI.FontFamily("Arial"));
        editor.RichTextBoxElement.ChangeFontSize(Unit.PointToDip(10));
        editor.RichTextBoxElement.ChangeFontStyle(Telerik.WinControls.RichTextEditor.UI.FontStyles.Normal);
        editor.RichTextBoxElement.ChangeFontWeight(Telerik.WinControls.RichTextEditor.UI.FontWeights.Normal);
     
        editor.RichTextBoxElement.ChangeParagraphLineSpacingType(LineSpacingType.Auto);
        editor.RichTextBoxElement.ChangeParagraphLineSpacing(0.5);
        editor.RichTextBoxElement.ChangeParagraphSpacingAfter(12);
        editor.DocumentInheritsDefaultStyleSettings = true;
    }

    Please, also check the following documentation resources providing detailed information on how RadRichTextEditor is functioning: Getting Started, FAQDocument Elements, Features.

    I hope this helps. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  26. Myoungsu
    Myoungsu avatar
    7 posts
    Member since:
    Jul 2015

    Posted 17 Sep 2015 in reply to Hristo Merdjanov Link to this post

    After I had call the function which you give on Form Loading event handler, I input text. But font is not changed.

    Should I call the function whenever inputting text?

    I hope that I set font at first time, and it kept by I change to another font.

     

  27. Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    711 posts

    Posted 18 Sep 2015 Link to this post

    Hello Myoungsu,

    Thank you for writing back.

    If you would like to change the font styling of the document, you need to make sure that the document you are importing is actually loaded. For the purpose, you can subscribe to the DocumentChanged event.

    In case you are working with an empty document and you call the method I last sent you in the Load event of the form, this should apply the settings and the new text you enter should be with the newly applied style.

    I am sending you attached my sample project as well as a gif file showing the result on my end. If you are still experiencing issues please send me a code snippet demonstrating your local setup.

    I hope this helps. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  28. Mahmoud
    Mahmoud avatar
    16 posts
    Member since:
    Jul 2013

    Posted 19 Oct 2015 in reply to Dimitar Link to this post

    Hello

    I have Problem  in raddock  ,documentContainer

    i need change color cannot changed  in c# winforms

  29. Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    711 posts

    Posted 20 Oct 2015 Link to this post

    Hello Mahmoud,

    Thank you for writing.

    This thread discusses setting fonts and changing sizes in RadRichTextEditor. We try to keep the forum threads and support tickets strictly focused on one topic. This way it is easier for us and also for the whole community to search for a solution of a scenario.

    Please open up a new forum thread or support ticket specifying RadDock as your product. In the meantime, you can check our online documentation: RadDock.

    Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  30. Rosa
    Rosa avatar
    3 posts
    Member since:
    Dec 2016

    Posted 1 day and 4 hours ago in reply to Troy Clemons Link to this post

    Hi guys

    i have question about telerik radrichedit;

    how we can set default paper size as A4 or A5 in code???

  31. Dimitar
    Admin
    Dimitar avatar
    1408 posts

    Posted 8 hours ago Link to this post

    Hello Rosa,

    Thank you for writing.

    The following snippet shows how you can change the page size:
    radRichTextEditor1.Document.LayoutMode = DocumentLayoutMode.Paged;
    radRichTextEditor1.ChangeSectionPageSize(PaperTypeConverter.ToSize(PaperTypes.A5));

    Should you have any other questions do not hesitate to ask.

    Regards,
    Dimitar
    Telerik by Progress
    Telerik UI for WinForms is ready for Visual Studio 2017 RC! Learn more.
Back to Top
UI for WinForms is Visual Studio 2017 Ready