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

Changing Default Font and Size

37 Answers 1596 Views
RichTextEditor
This is a migrated thread and some comments may be shown as answers.
Troy Clemons
Top achievements
Rank 1
Troy Clemons asked on 14 Aug 2015, 07:10 PM

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


 

37 Answers, 1 is accepted

Sort by
0
Troy Clemons
Top achievements
Rank 1
answered on 17 Aug 2015, 01:41 PM

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)

0
Dimitar
Telerik team
answered on 17 Aug 2015, 02:22 PM
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
0
Troy Clemons
Top achievements
Rank 1
answered on 17 Aug 2015, 03:35 PM

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
0
Dimitar
Telerik team
answered on 18 Aug 2015, 07:34 AM
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
0
Troy Clemons
Top achievements
Rank 1
answered on 18 Aug 2015, 12:00 PM
yes that changed the default editors color to red, but I need the inserted text to be red after insert.
0
Accepted
Dimitar
Telerik team
answered on 19 Aug 2015, 11:46 AM
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
0
Mahmoud
Top achievements
Rank 1
answered on 26 Aug 2015, 08:34 PM
radRichTextEditor1 how to make less spacing winforms
0
Troy Clemons
Top achievements
Rank 1
answered on 26 Aug 2015, 08:40 PM

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
0
Mahmoud
Top achievements
Rank 1
answered on 26 Aug 2015, 08:45 PM
sorry i need this c# and where put this code
0
Troy Clemons
Top achievements
Rank 1
answered on 26 Aug 2015, 08:50 PM

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

 

0
Mahmoud
Top achievements
Rank 1
answered on 26 Aug 2015, 08:58 PM

sorry sir 

plz find attach

what is the parameter importfile ?

0
Troy Clemons
Top achievements
Rank 1
answered on 26 Aug 2015, 09:03 PM

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

0
Mahmoud
Top achievements
Rank 1
answered on 26 Aug 2015, 09:08 PM
i have other error plz find attached
0
Troy Clemons
Top achievements
Rank 1
answered on 26 Aug 2015, 09:18 PM

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

0
Mahmoud
Top achievements
Rank 1
answered on 26 Aug 2015, 09:23 PM

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;
           
        }​

0
Mahmoud
Top achievements
Rank 1
answered on 27 Aug 2015, 07:17 AM

hello

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

plz find attached   

0
Mahmoud
Top achievements
Rank 1
answered on 27 Aug 2015, 08:42 AM

hello

how remove data or clear radRichTextEditor1 in c# 

0
Mahmoud
Top achievements
Rank 1
answered on 27 Aug 2015, 11:11 AM
how to remove text radRichTextEditor1. in c# 
0
Troy Clemons
Top achievements
Rank 1
answered on 27 Aug 2015, 11:50 AM
have you tried RadRichTextEditor1.Document =  NULL;
0
Mahmoud
Top achievements
Rank 1
answered on 27 Aug 2015, 11:55 AM
not working there exception "Object reference not set to an instance of an object."'.....??? 
0
Hristo
Telerik team
answered on 31 Aug 2015, 12:09 PM
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- 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
0
Myoungsu
Top achievements
Rank 1
answered on 17 Sep 2015, 06:34 AM

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

0
Hristo
Telerik team
answered on 17 Sep 2015, 01:57 PM
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
0
Myoungsu
Top achievements
Rank 1
answered on 18 Sep 2015, 12:13 AM

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.

 

0
Hristo
Telerik team
answered on 18 Sep 2015, 09:36 AM
Hello ,

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
0
Mahmoud
Top achievements
Rank 1
answered on 19 Oct 2015, 11:37 AM

Hello

I have Problem  in raddock  ,documentContainer

i need change color cannot changed  in c# winforms

0
Hristo
Telerik team
answered on 20 Oct 2015, 05:27 AM
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
0
rosa
Top achievements
Rank 1
answered on 04 Dec 2016, 05:05 PM

Hi guys

i have question about telerik radrichedit;

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

0
Dimitar
Telerik team
answered on 05 Dec 2016, 12:38 PM
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.
0
rosa
Top achievements
Rank 1
answered on 05 Dec 2016, 06:46 PM

Dear Dimitar,

thanks a million,,,

0
rosa
Top achievements
Rank 1
answered on 09 Dec 2016, 05:07 PM

ost

Hello guys

I've used above code for setting the page size and it s work but after this below code
radRichTextEditor1.Document=doc;

all the setting dont work

it means that when the text are entered in Radrichtext all of setting dont work
would you mind help me how i can fix it

0
Dimitar
Telerik team
answered on 12 Dec 2016, 10:50 AM
Hi Rosa,

If you assigning new document you need to change the settings again. Each document has is own PageSize.

I hope this information is useful. 

Regards,
Dimitar
Telerik by Progress
Telerik UI for WinForms is ready for Visual Studio 2017 RC! Learn more.
0
rosa
Top achievements
Rank 1
answered on 13 Jan 2017, 06:37 AM
Dear Admin,
I've used Radrichtexteditor in my project. In addition, I've used richtexteditorribbonbar and it is associated to radrichtexteditor.
In my project I get information from user through radRichTextEditor1 and convert context to Html for save in database (of course for this reason i used ImportHTML and exporttoHTML function ), my problem is : during execution , sometimes I face in this error ;
"{The function evaluation was disabled because of an out of memory exception.}"

I checked it and I figure out after each 10 times that user open the form contains of radrichtexteditor+richtexteditorribbonbar , this error is appeared.
How can I solve this problem?
I've attached the pic of error too, thanks a million for guiding me.

I have another problem too about opening the form which contain radrichtexteditor+richtexteditorribbonbar  , it takes to much time to open and it is no acceptable for user, what can I do to improve the time ?
0
Dimitar
Telerik team
answered on 13 Jan 2017, 11:22 AM
Hi Rosa,

If this form has many controls it, creating a new instance can be delayed a little bit. In this case, you can create a single instance and then just show/hide the form when it is needed. This will reduce the memory footprint as well. 

In addition, I have noticed that you have opened a new thread for this and we can continue to discuss this matter there. In general, there can be many reasons for the memory leak (a reference to another object, subscription to an event). The following article shows what you need to check in order to resolve this: Things to keep in mind when inspecting your application's memory usage.

I hope this information is useful. 

Regards,
Dimitar
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Harm
Top achievements
Rank 1
answered on 14 Jul 2017, 09:34 AM

Hello,

This topic is driving me mad!! I have been trying to get a default font and size for the RadTextBoxEditor for 3 days. I tried each and every piece of code that is described below but until now not with the desired result.

I know this is already an old topic, and it seems to be solved since the last post was of 2015, but I don't get the control to behave as I want.

I need the RichTextBoxEditor because of the MailMerge possibilities, but I don't want the user to change font size, type, colors or nothing, as the output will be a text file.

Due to company rules, I need a default font and size in the application.

To be short: I want the control to behave as a normal textbox, except for the mailmerge fields.

Scenario 1:
Set the default font family and size.
I load a document from Xaml with the XamlFormatProvider, OK.
I select the entire document, change the font family and font size. OK.
Now the user starts to type after the loaded text: to my horror font size 12 and original family again....

Scenario 2:
I don't load any document. Set the default font family and size.
The user starts to type, OK.
The user reconsiders, types Ctrl-A, Delete, starts typing again -> back to font size 12 and original family again...

I'm using version 2017 Q1...

What am I overlooking?

0
Dimitar
Telerik team
answered on 17 Jul 2017, 10:26 AM
Hi Harm,

In order the font to remain when the entire content is deleted, you need to change the "Normal" style. This should be done for each imported or new document as well:

StyleDefinition h1 = editor.Document.StyleRepository.GetValueOrNull("Normal");
h1.SpanProperties.FontSize = Unit.PointToDip(8.5);
h1.SpanProperties.FontWeight = Telerik.WinControls.RichTextEditor.UI.FontWeights.Normal;
h1.SpanProperties.FontFamily = new Telerik.WinControls.RichTextEditor.UI.FontFamily("Consolas");

I hope this will be useful.

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Harm
Top achievements
Rank 1
answered on 17 Jul 2017, 11:19 AM

Finally the solution I was looking for.

Thanks a million!

Tags
RichTextEditor
Asked by
Troy Clemons
Top achievements
Rank 1
Answers by
Troy Clemons
Top achievements
Rank 1
Dimitar
Telerik team
Mahmoud
Top achievements
Rank 1
Hristo
Telerik team
Myoungsu
Top achievements
Rank 1
rosa
Top achievements
Rank 1
Harm
Top achievements
Rank 1
Share this question
or