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:
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.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;
When we run the project, we see the following:
Hope that helps!