-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathFieldActions.vb
More file actions
81 lines (71 loc) · 3.77 KB
/
FieldActions.vb
File metadata and controls
81 lines (71 loc) · 3.77 KB
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
Imports System
Imports System.Collections.Generic
Imports System.Diagnostics
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraRichEdit.API.Native
Namespace RichEditDocumentServerAPIExample.CodeExamples
Friend Class FieldActions
Public Shared InsertFieldAction As System.Action(Of DevExpress.XtraRichEdit.RichEditDocumentServer) = AddressOf RichEditDocumentServerAPIExample.CodeExamples.FieldActions.InsertField
Public Shared ModifyFieldCodeAction As System.Action(Of DevExpress.XtraRichEdit.RichEditDocumentServer) = AddressOf RichEditDocumentServerAPIExample.CodeExamples.FieldActions.ModifyFieldCode
Public Shared CreateFieldFromRangeAction As System.Action(Of DevExpress.XtraRichEdit.RichEditDocumentServer) = AddressOf RichEditDocumentServerAPIExample.CodeExamples.FieldActions.CreateFieldFromRange
Private Shared Sub InsertField(ByVal wordProcessor As DevExpress.XtraRichEdit.RichEditDocumentServer)
#Region "#InsertField"
' Access a document.
Dim document As DevExpress.XtraRichEdit.API.Native.Document = wordProcessor.Document
' Start to edit the document.
document.BeginUpdate()
' Create the "DATE" field.
document.Fields.Create(document.Range.Start, "DATE")
' Update all fields in the main document body.
document.Fields.Update()
' Finalize to edit the document.
document.EndUpdate()
#End Region ' #InsertField
End Sub
Private Shared Sub ModifyFieldCode(ByVal wordProcessor As DevExpress.XtraRichEdit.RichEditDocumentServer)
#Region "#ModifyFieldCode"
' Access a document.
Dim document As DevExpress.XtraRichEdit.API.Native.Document = wordProcessor.Document
' Start to edit the document.
document.BeginUpdate()
' Create the "DATE" field.
document.Fields.Create(document.CaretPosition, "DATE")
' Finalize to edit the document.
document.EndUpdate()
' Check all fields in the document.
For i As Integer = 0 To document.Fields.Count - 1
' Access a field code.
Dim fieldCode As String = document.GetText(document.Fields(CInt((i))).CodeRange)
' Check whether a field code is "DATE".
If Equals(fieldCode, "DATE") Then
' Set the document position to the end of the field code range.
Dim position As DevExpress.XtraRichEdit.API.Native.DocumentPosition = document.Fields(CInt((i))).CodeRange.[End]
' Specify the date and time format for the field.
document.InsertText(position, " \@ ""M / d / yyyy HH: mm:ss""")
End If
Next
' Update all fields in the main document body.
document.Fields.Update()
#End Region ' #ModifyFieldCode
End Sub
Private Shared Sub CreateFieldFromRange(ByVal wordProcessor As DevExpress.XtraRichEdit.RichEditDocumentServer)
#Region "#CreateFieldFromRange"
' Access a document.
Dim document As DevExpress.XtraRichEdit.API.Native.Document = wordProcessor.Document
' Start to edit the document.
document.BeginUpdate()
' Append text to the document.
document.AppendText("SYMBOL 0x54 \f Wingdings \s 24")
' Finalize to edit the document.
document.EndUpdate()
' Convert inserted text to a field.
document.Fields.Create(document.Paragraphs(CInt((0))).Range)
' Update all fields in the main document body.
document.Fields.Update()
#End Region ' #CreateFieldFromRange
End Sub
End Class
End Namespace