/
ShapesActions.vb
106 lines (100 loc) · 4.84 KB
/
ShapesActions.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
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
Imports DevExpress.XtraRichEdit.API.Native
Imports System
Imports System.Collections.Generic
Imports System.IO
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports System.Windows
Imports System.Windows.Media.Imaging
Imports System.Windows.Resources
Namespace DXRichEditControlAPISample.CodeExamples
Friend Class ShapesActions
Private Shared Sub AddFloatingPicture(ByVal document As Document)
' #Region "#AddFloatingPicture"
document.AppendText("Line One" & vbLf & "Line Two" & vbLf & "Line Three")
Dim streamResInfo As StreamResourceInfo = Application.GetResourceStream(New Uri("beverages.png", UriKind.Relative))
If streamResInfo IsNot Nothing Then
Using s As Stream = streamResInfo.Stream
Dim myPicture As Shape = document.Shapes.InsertPicture(document.CreatePosition(15), DocumentImageSource.FromStream(s))
myPicture.HorizontalAlignment = ShapeHorizontalAlignment.Center
End Using
End If
' #End Region ' #AddFloatingPicture
End Sub
Private Shared Sub FloatingPictureOffset(ByVal document As Document)
' #Region "#FloatingPictureOffset"
document.LoadDocument("Documents//Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml)
document.Unit = DevExpress.Office.DocumentUnit.Centimeter
Dim myPicture As Shape = document.Shapes(1)
' Clear the qualitative positioning to allow positioning by specifying the numerical offset.
myPicture.HorizontalAlignment = ShapeHorizontalAlignment.None
myPicture.VerticalAlignment = ShapeVerticalAlignment.None
' Specify the reference item for positioning.
myPicture.RelativeHorizontalPosition = ShapeRelativeHorizontalPosition.LeftMargin
myPicture.RelativeVerticalPosition = ShapeRelativeVerticalPosition.TopMargin
' Specify the offset value.
myPicture.Offset = New System.Drawing.PointF(4.5F, 2.0F)
' #End Region ' #FloatingPictureOffset
End Sub
Private Shared Sub ChangeZorderAndWrapping(ByVal document As Document)
' #Region "#ChangeZorderAndWrapping"
document.LoadDocument("Documents//Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml)
Dim myPicture As Shape = document.Shapes(1)
myPicture.VerticalAlignment = ShapeVerticalAlignment.Top
myPicture.ZOrder = document.Shapes(0).ZOrder - 1
myPicture.TextWrapping = TextWrappingType.BehindText
' #End Region ' #ChangeZorderAndWrapping
End Sub
Private Shared Sub AddTextBox(ByVal document As Document)
' #Region "#AddTextBox"
document.AppendText("Line One" & vbLf & "Line Two" & vbLf & "Line Three")
Dim myTextBox As Shape = document.Shapes.InsertTextBox(document.CreatePosition(15))
myTextBox.HorizontalAlignment = ShapeHorizontalAlignment.Center
' Specify the text box background color.
myTextBox.Fill.Color = System.Drawing.Color.WhiteSmoke
' Draw a border around the text box.
myTextBox.Line.Color = System.Drawing.Color.Black
myTextBox.Line.Thickness = 1
' Modify text box content.
Dim textBoxDocument As SubDocument = myTextBox.ShapeFormat.TextBox.Document
textBoxDocument.AppendText("TextBox Text")
Dim cp As CharacterProperties = textBoxDocument.BeginUpdateCharacters(textBoxDocument.Range.Start, 7)
cp.ForeColor = System.Drawing.Color.Orange
cp.FontSize = 24
textBoxDocument.EndUpdateCharacters(cp)
' #End Region ' #AddTextBox
End Sub
Private Shared Sub InsertRichTextInTextBox(ByVal document As Document)
' #Region "#InsertRichTextInTextBox"
document.LoadDocument("Documents//Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml)
Dim myTextBox As Shape = document.Shapes(0)
' Allow text box resize to fit contents.
myTextBox.ShapeFormat.TextBox.HeightRule = TextBoxSizeRule.Auto
Dim boxedDocument As SubDocument = myTextBox.ShapeFormat.TextBox.Document
Dim appendPosition As Integer = myTextBox.ShapeFormat.TextBox.Document.Range.End.ToInt()
' Append the second paragraph of the main document to the boxed text.
Dim newRange As DocumentRange = boxedDocument.AppendDocumentContent(document.Paragraphs(1).Range)
boxedDocument.Paragraphs.Insert(newRange.Start)
' Insert an image form the main document into the text box.
boxedDocument.Images.Insert(boxedDocument.CreatePosition(appendPosition), document.Images(0).Image.NativeImage)
' Resize the image so that its size equals the image in the main document.
boxedDocument.Images(0).Size = document.Images(0).Size
' #End Region ' #InsertRichTextInTextBox
End Sub
Private Shared Sub RotateAndResize(ByVal document As Document)
' #Region "#RotateAndResize"
document.LoadDocument("Documents//Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml)
For Each s As Shape In document.Shapes
' Rotate a text box and resize a floating picture.
If s.Type = ShapeType.Picture Then
s.RotationAngle = 45
Else
s.ScaleX = 0.1F
s.ScaleY = 0.1F
End If
Next s
' #End Region ' #RotateAndResize
End Sub
End Class
End Namespace