Blogs

Rachel Reese - DevExpress Scheduler & RichEdit Blog

WinForms RichEdit: Updating the Font

     

I've had a couple questions lately on how to update paragraph styles after a document has been loaded, or when using our Document Server.

I've discussed before how to update the default font for an empty document, but what if you just want to change the font on a pre-loaded document? Just as easy. If we have the following document:

Original Font, before updating

Then, to update the title and author, we first need to define the range of characters that contains this information:

Document doc = richEditControl1.Document;
DocumentRange range = doc.Paragraphs[1].Range;

And then, update the range using the BeginUpdateCharacters and EndUpdateCharacters methods:

CharacterProperties cp = doc.BeginUpdateCharacters(range);
cp.FontName = "French Script MT";
cp.FontSize = 24;
cp.ForeColor = Color.DarkOliveGreen;
cp.BackColor = Color.BlanchedAlmond;
cp.Underline = UnderlineType.ThickLongDashed;
cp.UnderlineColor = Color.DarkViolet;
doc.EndUpdateCharacters(cp);

When we run the project, we see the following: 

With a new font, after updating

Hope that helps!

Published Oct 05 2011, 02:22 PM by Rachel Reese (DevExpress)
Bookmark and Share

Comments

 

Peter van der Veen said:

How can this be done for a whole document instead of only one paragraph?

April 11, 2012 8:40 AM
More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 7:30am and 4:30pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.