/
Shapes.cs
122 lines (111 loc) · 5.43 KB
/
Shapes.cs
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
using DevExpress.XtraRichEdit.API.Native;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RichEditAPISample.CodeExamples
{
class ShapesActions
{
static void AddFloatingPicture(Document document)
{
#region #AddFloatingPicture
document.AppendText("Line One\nLine Two\nLine Three");
Shape myPicture = document.Shapes.InsertPicture(document.CreatePosition(15),
DocumentImageSource.FromFile("beverages.png"));
myPicture.HorizontalAlignment = ShapeHorizontalAlignment.Center;
#endregion #AddFloatingPicture
}
static void FloatingPictureOffset(Document document)
{
#region #FloatingPictureOffset
document.LoadDocument("Documents//Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml);
document.Unit = DevExpress.Office.DocumentUnit.Centimeter;
Shape myPicture = 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);
#endregion #FloatingPictureOffset
}
static void ChangeZorderAndWrapping(Document document)
{
#region #ChangeZorderAndWrapping
document.LoadDocument("Documents//Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml);
Shape myPicture = document.Shapes[1];
myPicture.VerticalAlignment = ShapeVerticalAlignment.Top;
myPicture.ZOrder = document.Shapes[0].ZOrder - 1;
myPicture.TextWrapping = TextWrappingType.BehindText;
#endregion #ChangeZorderAndWrapping
}
static void AddTextBox(Document document)
{
#region #AddTextBox
document.AppendText("Line One\nLine Two\nLine Three");
Shape myTextBox = 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.
SubDocument textBoxDocument = myTextBox.ShapeFormat.TextBox.Document;
textBoxDocument.AppendText("TextBox Text");
CharacterProperties cp = textBoxDocument.BeginUpdateCharacters(textBoxDocument.Range.Start, 7);
cp.ForeColor = System.Drawing.Color.Orange;
cp.FontSize = 24;
textBoxDocument.EndUpdateCharacters(cp);
#endregion #AddTextBox
}
static void InsertRichTextInTextBox(Document document)
{
#region #InsertRichTextInTextBox
document.LoadDocument("Documents//Grimm.docx");
Shape myTextBox = document.Shapes[0];
// Allow text box resize to fit contents.
myTextBox.ShapeFormat.TextBox.HeightRule = TextBoxSizeRule.Auto;
SubDocument boxedDocument = myTextBox.ShapeFormat.TextBox.Document;
int appendPosition = myTextBox.ShapeFormat.TextBox.Document.Range.End.ToInt();
// Append the second paragraph of the main document to the boxed text.
DocumentRange newRange = 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), DocumentImageSource.FromImage(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;
#endregion #InsertRichTextInTextBox
}
static void RotateAndResize(Document document)
{
#region #RotateAndResize
document.LoadDocument("Documents//Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml);
foreach (Shape s in document.Shapes)
{
// Rotate a text box and resize a floating picture.
if (s.Type == ShapeType.Picture)
{
s.RotationAngle = 45;
}
else
{
s.ScaleX = 0.1f;
s.ScaleY = 0.1f;
}
}
#endregion #RotateAndResize
}
static void SelectShape(Document document)
{
#region #SelectShape
document.LoadDocument("Documents//Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml);
document.Selection = document.Shapes[0].Range;
#endregion #SelectShape
}
}
}