/
Notes.cs
134 lines (103 loc) · 5.27 KB
/
Notes.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;
namespace RichEditAPISample.CodeExamples
{
class NotesActions
{
static void InsertFootnotes(Document document)
{
#region #InsertFootnotes
document.LoadDocument("Documents//Grimm.docx");
//Insert a footnote at the end of the 6th paragraph:
DocumentPosition footnotePosition = document.CreatePosition(document.Paragraphs[5].Range.End.ToInt() - 1);
document.Footnotes.Insert(footnotePosition);
//Insert a footnote at the end of the 8th paragraph with a custom mark:
DocumentPosition footnoteWithCustomMarkPosition = document.CreatePosition(document.Paragraphs[7].Range.End.ToInt() - 1);
document.Footnotes.Insert(footnoteWithCustomMarkPosition, "\u00BA");
#endregion #InsertFootnotes
}
static void InsertEndnotes(Document document)
{
#region #InsertEndnotes
document.LoadDocument("Documents//Grimm.docx");
//Insert an endnote at the end of the second last paragraph paragraph:
DocumentPosition endnotePosition = document.CreatePosition(document.Paragraphs[document.Paragraphs.Count - 2].Range.End.ToInt() - 1);
document.Endnotes.Insert(endnotePosition);
//Insert an endnote with a custom mark:
DocumentPosition endnoteWithCustomMarkPosition = document.CreatePosition(document.Paragraphs[document.Paragraphs.Count - 3].Range.End.ToInt() - 1);
document.Endnotes.Insert(endnoteWithCustomMarkPosition, "\u00BA");
#endregion #InsertEndnotes
}
static void EditFootnote(Document document)
{
#region #EditFootnote
document.LoadDocument("Documents//Grimm.docx");
//Access the first fottnote's content:
SubDocument footnote = document.Footnotes[0].BeginUpdate();
//Exclude the reference mark and the space after it from the range to be edited:
DocumentRange noteTextRange = footnote.CreateRange(footnote.Range.Start.ToInt() + 2, footnote.Range.Length
- 2);
//Clear the range:
footnote.Delete(noteTextRange);
//Append a new text:
footnote.AppendText("the text is removed");
//Finalize the update:
document.Footnotes[0].EndUpdate(footnote);
#endregion #EditFootnote
}
static void EditEndnote(Document document)
{
#region #EditEndnote
document.LoadDocument("Documents//Grimm.docx");
//Access the first endnote's content:
SubDocument endnote = document.Endnotes[0].BeginUpdate();
//Exclude the reference mark and the space after it from the range to be edited:
DocumentRange noteTextRange = endnote.CreateRange(endnote.Range.Start.ToInt() + 2, endnote.Range.Length
- 2);
//Access the range's character properties:
CharacterProperties characterProperties = endnote.BeginUpdateCharacters(noteTextRange);
characterProperties.ForeColor = System.Drawing.Color.Red;
characterProperties.Italic = true;
//Finalize the character options update:
endnote.EndUpdateCharacters(characterProperties);
//Finalize the endnote update:
document.Endnotes[0].EndUpdate(endnote);
#endregion #EditEndnote
}
static void EditSeparator(Document document)
{
#region #EditSeparator
document.LoadDocument("Documents//Grimm.docx");
//Check whether the footnotes already have a separator:
if (document.Footnotes.HasSeparator(NoteSeparatorType.Separator))
{
//Initiate the update session:
SubDocument noteSeparator = document.Footnotes.BeginUpdateSeparator(NoteSeparatorType.Separator);
//Clear the separator range:
noteSeparator.Delete(noteSeparator.Range);
//Append a new text:
noteSeparator.AppendText("***");
CharacterProperties characterProperties = noteSeparator.BeginUpdateCharacters(noteSeparator.Range);
characterProperties.ForeColor = System.Drawing.Color.Blue;
noteSeparator.EndUpdateCharacters(characterProperties);
//Finalize the update:
document.Footnotes.EndUpdateSeparator(noteSeparator);
}
#endregion #EditSeparator
}
static void RemoveNotes(Document document)
{
#region #RemoveNotes
document.LoadDocument("Documents//Grimm.docx");
//Remove first footnote:
document.Footnotes.RemoveAt(0);
//Remove all custom endnotes:
for (int i = document.Endnotes.Count - 1; i >= 0; i--)
{
if (document.Endnotes[i].IsCustom)
document.Endnotes.Remove(document.Endnotes[i]);
}
#endregion #RemoveNotes
}
}
}