-
Notifications
You must be signed in to change notification settings - Fork 0
/
FormattingActions.vb
75 lines (71 loc) · 3.13 KB
/
FormattingActions.vb
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
Imports DevExpress.XtraRichEdit.API.Native
Imports System
Imports System.Drawing
Namespace DXRichEditControlAPISample.CodeExamples
Public Module FormattingActions
Private Sub FormatText(ByVal document As Document)
' #Region "#FormatText"
document.BeginUpdate()
document.AppendText("Normal" & vbLf & "Formatted" & vbLf & "Normal")
document.EndUpdate()
Dim range As DocumentRange = document.Paragraphs(1).Range
Dim cp As CharacterProperties = 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
document.EndUpdateCharacters(cp)
' #End Region ' #FormatText
End Sub
Private Sub ResetCharacterFormatting(ByVal document As 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.
Dim range As DocumentRange = document.Paragraphs(0).Range
Dim cp As CharacterProperties = document.BeginUpdateCharacters(range)
cp.Reset(CharacterPropertiesMask.FontSize Or CharacterPropertiesMask.FontName)
document.EndUpdateCharacters(cp)
' #End Region ' #ResetCharacterFormatting
End Sub
Private Sub FormatParagraph(ByVal document As Document)
' #Region "#FormatParagraph"
document.BeginUpdate()
document.AppendText("Modified Paragraph" & vbLf & "Normal" & vbLf & "Normal")
document.EndUpdate()
Dim pos As DocumentPosition = document.Range.Start
Dim range As DocumentRange = document.CreateRange(pos, 0)
Dim pp As ParagraphProperties = 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"
Dim tbiColl As TabInfoCollection = pp.BeginUpdateTabs(True)
Dim tbi As New TabInfo()
tbi.Alignment = TabAlignmentType.Center
tbi.Position = DevExpress.Office.Utils.Units.InchesToDocumentsF(1.5F)
tbiColl.Add(tbi)
pp.EndUpdateTabs(tbiColl)
document.EndUpdateParagraphs(pp)
' #End Region ' #FormatParagraph
End Sub
Private Sub ResetParagraphFormatting(ByVal document As 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.
Dim range As DocumentRange = document.Paragraphs(0).Range
Dim cp As ParagraphProperties = document.BeginUpdateParagraphs(range)
cp.Reset(ParagraphPropertiesMask.Alignment Or ParagraphPropertiesMask.FirstLineIndent)
document.EndUpdateParagraphs(cp)
' #End Region ' #ResetParagraphFormatting
End Sub
End Module
End Namespace