-
Notifications
You must be signed in to change notification settings - Fork 4
/
HeaderAndFooter.vb
74 lines (68 loc) · 3.6 KB
/
HeaderAndFooter.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
Imports DevExpress.XtraRichEdit.API.Native
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Namespace RichEditAPISample.CodeExamples
Friend Class HeaderAndFooterActions
Private Shared Sub CreateHeader(ByVal document As Document)
' #Region "#CreateHeader"
Dim firstSection As Section = document.Sections(0)
' Create an empty header.
Dim newHeader As SubDocument = firstSection.BeginUpdateHeader()
firstSection.EndUpdateHeader(newHeader)
' Check whether the document already has a header (the same header for all pages).
If firstSection.HasHeader(HeaderFooterType.Primary) Then
Dim headerDocument As SubDocument = firstSection.BeginUpdateHeader()
document.ChangeActiveDocument(headerDocument)
document.CaretPosition = headerDocument.CreatePosition(0)
firstSection.EndUpdateHeader(headerDocument)
End If
' #End Region ' #CreateHeader
End Sub
Private Shared Sub ModifyHeader(ByVal document As Document)
' #Region "#ModifyHeader"
document.AppendSection()
Dim firstSection As Section = document.Sections(0)
' Modify the header of the HeaderFooterType.First type.
Dim myHeader As SubDocument = firstSection.BeginUpdateHeader(HeaderFooterType.First)
Dim range As DocumentRange = myHeader.InsertText(myHeader.CreatePosition(0), " PAGE NUMBER ")
Dim fld As Field = myHeader.Fields.Create(range.End, "PAGE \* ARABICDASH")
myHeader.Fields.Update()
firstSection.EndUpdateHeader(myHeader)
' Display the header of the HeaderFooterType.First type on the first page.
firstSection.DifferentFirstPage = True
' #End Region ' #ModifyHeader
End Sub
Private Shared Sub CreateFooter(ByVal document As Document)
' #Region "#CreateFooter"
Dim firstSection As Section = document.Sections(0)
' Create an empty footer.
Dim newFooter As SubDocument = firstSection.BeginUpdateFooter()
firstSection.EndUpdateFooter(newFooter)
' Check whether the document already has a footer (the same footer for all pages).
If firstSection.HasFooter(HeaderFooterType.Primary) Then
Dim footerDocument As SubDocument = firstSection.BeginUpdateFooter()
document.ChangeActiveDocument(footerDocument)
document.CaretPosition = footerDocument.CreatePosition(0)
firstSection.EndUpdateFooter(footerDocument)
End If
' #End Region ' #CreateFooter
End Sub
Private Shared Sub ModifyFooter(ByVal document As Document)
' #Region "#ModifyFooter"
document.AppendSection()
Dim firstSection As Section = document.Sections(0)
' Modify the footer of the HeaderFooterType.First type.
Dim myFooter As SubDocument = firstSection.BeginUpdateFooter(HeaderFooterType.First)
Dim range As DocumentRange = myFooter.InsertText(myFooter.CreatePosition(0), " PAGE NUMBER ")
Dim fld As Field = myFooter.Fields.Create(range.End, "PAGE \* ARABICDASH")
myFooter.Fields.Update()
firstSection.EndUpdateHeader(myFooter)
' Display the footer of the HeaderFooterType.First type on the first page.
firstSection.DifferentFirstPage = True
' #End Region ' #ModifyFooter
End Sub
End Class
End Namespace