-
Notifications
You must be signed in to change notification settings - Fork 0
/
DocumentPropertiesActions.vb
72 lines (64 loc) · 3.3 KB
/
DocumentPropertiesActions.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
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports DevExpress.XtraRichEdit.API.Native
Imports DevExpress.Xpf.RichEdit
Namespace DXRichEditControlAPISample.CodeExamples
Friend Class DocumentPropertiesActions
Private Shared Sub StandardDocumentProperties(ByVal document As Document)
' #Region "#StandardDocumentProperties"
document.BeginUpdate()
document.DocumentProperties.Creator = "John Doe"
document.DocumentProperties.Title = "Inserting Custom Properties"
document.DocumentProperties.Category = "TestDoc"
document.DocumentProperties.Description = "This code demonstrates API to modify and display standard document properties."
document.Fields.Create(document.AppendText(vbLf & "AUTHOR: ").End, "AUTHOR")
document.Fields.Create(document.AppendText(vbLf & "TITLE: ").End, "TITLE")
document.Fields.Create(document.AppendText(vbLf & "COMMENTS: ").End, "COMMENTS")
document.Fields.Create(document.AppendText(vbLf & "CREATEDATE: ").End, "CREATEDATE")
document.Fields.Create(document.AppendText(vbLf & "Category: ").End, "DOCPROPERTY Category")
document.Fields.Update()
document.EndUpdate()
' #End Region ' #StandardDocumentProperties
End Sub
Private Shared Sub CustomDocumentProperties(ByVal document As Document)
' #Region "#CustomDocumentProperties"
document.BeginUpdate()
document.AppendText("A new value of MyBookmarkProperty is obtained from here: NEWVALUE!" & vbLf)
document.Bookmarks.Create(document.FindAll("NEWVALUE!", SearchOptions.CaseSensitive)(0), "bmOne")
document.AppendText(vbLf & "MyNumericProperty: ")
document.Fields.Create(document.Range.End, "DOCVARIABLE CustomProperty MyNumericProperty")
document.AppendText(vbLf & "MyStringProperty: ")
document.Fields.Create(document.Range.End, "DOCVARIABLE CustomProperty MyStringProperty")
document.AppendText(vbLf & "MyBooleanProperty: ")
document.Fields.Create(document.Range.End, "DOCVARIABLE CustomProperty MyBooleanProperty")
document.AppendText(vbLf & "MyBookmarkProperty: ")
document.Fields.Create(document.Range.End, "DOCVARIABLE CustomProperty MyBookmarkProperty")
document.EndUpdate()
document.CustomProperties("MyNumericProperty") = 123.45
document.CustomProperties("MyStringProperty") = "The Final Answer"
document.CustomProperties("MyBookmarkProperty") = document.Bookmarks(0)
document.CustomProperties("MyBooleanProperty") = True
AddHandler document.CalculateDocumentVariable, AddressOf DocumentPropertyDisplayHelper.OnCalculateDocumentVariable
document.Fields.Update()
' #End Region ' #CustomDocumentProperties
End Sub
#Region "#@CustomDocumentProperties"
Private Class DocumentPropertyDisplayHelper
Public Shared Sub OnCalculateDocumentVariable(ByVal sender As Object, ByVal e As DevExpress.XtraRichEdit.CalculateDocumentVariableEventArgs)
If e.Arguments.Count = 0 OrElse e.VariableName <> "CustomProperty" Then
Return
End If
Dim name As String = e.Arguments(0).Value
Dim customProperty = DirectCast(sender, DevExpress.Xpf.RichEdit.RichEditControl).Document.CustomProperties(name)
If customProperty IsNot Nothing Then
e.Value = customProperty.ToString()
End If
e.Handled = True
End Sub
End Class
#End Region ' #@CustomDocumentProperties
End Class
End Namespace