-
Notifications
You must be signed in to change notification settings - Fork 4
/
Formatting.cs
96 lines (87 loc) · 4.08 KB
/
Formatting.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using DevExpress.XtraRichEdit.API.Native;
using System;
using System.Drawing;
namespace RichEditAPISample.CodeExamples
{
public static class FormattingActions
{
static void FormatText(Document document)
{
#region #FormatText
document.BeginUpdate();
document.AppendText("Normal\nFormatted\nNormal");
document.EndUpdate();
// The target range is the second paragraph
DocumentRange range = document.Paragraphs[1].Range;
// Create and customize an object
// that sets character formatting for the selected range
CharacterProperties cp = document.BeginUpdateCharacters(range);
cp.FontName = "Comic Sans MS";
cp.FontSize = 18;
cp.ForeColor = Color.Blue;
cp.BackColor = Color.Snow;
cp.Underline = UnderlineType.DoubleWave;
cp.UnderlineColor = Color.Red;
// Finalize modifications
// with this method call
document.EndUpdateCharacters(cp);
#endregion #FormatText
}
static void ResetCharacterFormatting(Document document)
{
#region #ResetCharacterFormatting
document.LoadDocument("Documents//Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml);
// Set font size and font name of the characters in the first paragraph to default.
// Other character properties remain intact.
DocumentRange range = document.Paragraphs[0].Range;
CharacterProperties cp = document.BeginUpdateCharacters(range);
cp.Reset(CharacterPropertiesMask.FontSize | CharacterPropertiesMask.FontName);
document.EndUpdateCharacters(cp);
#endregion #ResetCharacterFormatting
}
static void FormatParagraph(Document document)
{
#region #FormatParagraph
document.BeginUpdate();
document.AppendText("Modified Paragraph\nNormal\nNormal");
document.EndUpdate();
//The target range is the first paragraph
DocumentPosition pos = document.Range.Start;
DocumentRange range = document.CreateRange(pos, 0);
// Create and customize an object
// that sets character formatting for the selected range
ParagraphProperties pp = document.BeginUpdateParagraphs(range);
// Center paragraph
pp.Alignment = ParagraphAlignment.Center;
// Set triple spacing
pp.LineSpacingType = ParagraphLineSpacing.Multiple;
pp.LineSpacingMultiplier = 3;
// Set left indent at 0.5".
// Default unit is 1/300 of an inch (a document unit).
pp.LeftIndent = DevExpress.Office.Utils.Units.InchesToDocumentsF(0.5f);
// Set tab stop at 1.5"
TabInfoCollection tbiColl = pp.BeginUpdateTabs(true);
TabInfo tbi = new DevExpress.XtraRichEdit.API.Native.TabInfo();
tbi.Alignment = TabAlignmentType.Center;
tbi.Position = DevExpress.Office.Utils.Units.InchesToDocumentsF(1.5f);
tbiColl.Add(tbi);
pp.EndUpdateTabs(tbiColl);
//Finalize modifications
// with this method call
document.EndUpdateParagraphs(pp);
#endregion #FormatParagraph
}
static void ResetParagraphFormatting(Document document)
{
#region #ResetParagraphFormatting
document.LoadDocument("Documents//Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml);
// Set alignment and indentation of the first line in the first paragraph to default.
// Other paragraph properties remain intact.
DocumentRange range = document.Paragraphs[0].Range;
ParagraphProperties cp = document.BeginUpdateParagraphs(range);
cp.Reset(ParagraphPropertiesMask.Alignment | ParagraphPropertiesMask.FirstLineIndent);
document.EndUpdateParagraphs(cp);
#endregion #ResetParagraphFormatting
}
}
}