/
Form1.cs
278 lines (219 loc) · 11.4 KB
/
Form1.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
using DevExpress.Office.Utils;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraRichEdit.API.Native;
using System.Drawing;
namespace TablesSimpleExample
{
public partial class Form1 : RibbonForm
{
Table table;
Document document;
public Form1()
{
InitializeComponent();
document = richEditControl1.Document;
}
private void createTablebtn_ItemClick(object sender, ItemClickEventArgs e)
{
// Create a new table and specify its layout type
table = document.Tables.Create(document.Range.End, 2, 2);
// Add new rows to the table
table.Rows.InsertBefore(0);
table.Rows.InsertAfter(0);
// Add a new column to the table
table.Rows[0].Cells.Append();
table.Rows[0].Cells.InsertBefore(0);
table.Rows[0].FirstCell.PreferredWidthType = WidthType.Auto;
table.Rows[0].Cells[1].PreferredWidthType = WidthType.Fixed;
table.Rows[0].Cells[1].PreferredWidth = Units.InchesToDocumentsF(0.8f);
// Set the second column width and cell height
table[0, 2].PreferredWidthType = WidthType.Fixed;
table[0, 2].PreferredWidth = Units.InchesToDocumentsF(5f);
table[0, 2].HeightType = HeightType.Exact;
table[0, 2].Height = Units.InchesToDocumentsF(0.5f);
//Set the third column width
table.Rows[0].LastCell.PreferredWidthType = WidthType.Fixed;
table.Rows[0].LastCell.PreferredWidth = Units.InchesToDocumentsF(0.8f);
}
private void mergeBtn_ItemClick(object sender, ItemClickEventArgs e)
{
table.BeginUpdate();
// Split cell into 8
table[3, 2].Split(4, 2);
// Merge cells
table.MergeCells(table[4, 2], table[4, 3]);
table.MergeCells(table[6, 2], table[6, 3]);
table.MergeCells(table[2, 0], table[6, 0]);
table.EndUpdate();
}
private void repeatRowsBtn_ItemClick(object sender, ItemClickEventArgs e)
{
table.BeginUpdate();
// Repeat first three rows as header:
table.Rows[0].RepeatAsHeaderRow = true;
table.Rows[1].RepeatAsHeaderRow = true;
table.Rows[2].RepeatAsHeaderRow = true;
// Break last row across pages:
table.LastRow.BreakAcrossPages = true;
table.EndUpdate();
}
private void wrapTextBtn_ItemClick(object sender, ItemClickEventArgs e)
{
table.BeginUpdate();
// Wrap text around the table
table.TextWrappingType = TableTextWrappingType.Around;
// Specify vertical alignment:
table.RelativeVerticalPosition = TableRelativeVerticalPosition.Paragraph;
table.VerticalAlignment = TableVerticalAlignment.None;
table.OffsetYRelative = Units.InchesToDocumentsF(2f);
// Specify horizontal alignment:
table.RelativeHorizontalPosition = TableRelativeHorizontalPosition.Margin;
table.HorizontalAlignment = TableHorizontalAlignment.Center;
// Set distance between the text and the table:
table.MarginBottom = Units.InchesToDocumentsF(0.3f);
table.MarginLeft = Units.InchesToDocumentsF(0.3f);
table.MarginTop = Units.InchesToDocumentsF(0.3f);
table.MarginRight = Units.InchesToDocumentsF(0.3f);
table.EndUpdate();
}
private void insertContentBtn_ItemClick(object sender, ItemClickEventArgs e)
{
// Insert header data
document.InsertSingleLineText(table.Rows[0].Cells[2].Range.Start, "Active Customers");
document.InsertSingleLineText(table[2, 1].Range.Start, "Photo");
document.InsertSingleLineText(table[2, 0].Range.Start, "Customer №1");
document.InsertSingleLineText(table[2, 2].Range.Start, "Customer Info");
document.InsertSingleLineText(table[2, 3].Range.Start, "Rentals");
// Insert the customer photo
document.Images.Insert(table[3, 1].Range.Start, DocumentImageSource.FromFile("photo.png"));
// Insert the customer info
document.InsertText(table[3, 2].Range.Start, "Ryan Anita W");
document.InsertText(table[3, 3].Range.Start, "Intermediate");
document.InsertText(table[4, 2].Range.Start, "3/28/1984");
document.InsertText(table[5, 2].Range.Start, "anita_ryan@dxvideorent.com");
document.InsertText(table[5, 3].Range.Start, "(555)421-0059");
document.InsertText(table[6, 2].Range.Start, "5119 Beryl Dr, San Antonio, TX 78212");
document.InsertSingleLineText(table[3, 4].Range.Start, "18");
}
private void formatContentBtn_ItemClick(object sender, ItemClickEventArgs e)
{
// Apply formatting to the "Active Customers" cell
CharacterProperties properties = document.BeginUpdateCharacters(table[0, 2].ContentRange);
properties.FontName = "Segoe UI";
properties.FontSize = 16;
document.EndUpdateCharacters(properties);
ParagraphProperties alignment = document.BeginUpdateParagraphs(table[0, 2].ContentRange);
alignment.Alignment = ParagraphAlignment.Center;
document.EndUpdateParagraphs(alignment);
table[0, 1].VerticalAlignment = TableCellVerticalAlignment.Center;
// Apply formatting to the header cells
CharacterProperties headerRowProperties = document.BeginUpdateCharacters(table.Rows[2].Range);
headerRowProperties.FontName = "Segoe UI";
headerRowProperties.FontSize = 11;
headerRowProperties.ForeColor = Color.FromArgb(212, 236, 183);
document.EndUpdateCharacters(headerRowProperties);
ParagraphProperties headerRowParagraphProperties = document.BeginUpdateParagraphs(table.Rows[2].Range);
headerRowParagraphProperties.Alignment = ParagraphAlignment.Center;
document.EndUpdateParagraphs(headerRowParagraphProperties);
// Apply formatting to the customer info cells
DocumentRange targetRange = document.CreateRange(table[3, 2].Range.Start, table[6, 3].Range.Start.ToInt() - table[3, 2].Range.Start.ToInt());
CharacterProperties infoProperties = document.BeginUpdateCharacters(targetRange);
infoProperties.FontSize = 8;
infoProperties.FontName = "Segoe UI";
infoProperties.ForeColor = Color.FromArgb(111, 116, 106);
document.EndUpdateCharacters(infoProperties);
// Format "Rentals" cells
CharacterProperties rentalFormat = document.BeginUpdateCharacters(table[3, 4].Range);
rentalFormat.FontSize = 28;
rentalFormat.Bold = true;
document.EndUpdateCharacters(rentalFormat);
ParagraphProperties rentalAlignment = document.BeginUpdateParagraphs(table[3, 4].Range);
rentalAlignment.Alignment = ParagraphAlignment.Center;
document.EndUpdateParagraphs(rentalAlignment);
table[3, 4].VerticalAlignment = TableCellVerticalAlignment.Center;
}
private void customizeBtn_ItemClick(object sender, ItemClickEventArgs e)
{
table.BeginUpdate();
// Call the ChangeCellBorderColor method
// for every cell in the first two rows
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < table.Rows[i].Cells.Count; j++)
{
// Specify the border style and the background color for the header cells
table[i, j].Borders.Bottom.LineStyle = TableBorderLineStyle.None;
table[i, j].Borders.Left.LineStyle = TableBorderLineStyle.None;
table[i, j].Borders.Right.LineStyle = TableBorderLineStyle.None;
table[i, j].Borders.Top.LineStyle = TableBorderLineStyle.None;
table[i, j].BackgroundColor = Color.Transparent;
}
}
TableRow targetRow = table.Rows[2];
targetRow.Cells[1].BackgroundColor = Color.FromArgb(99, 122, 110);
targetRow.Cells[2].BackgroundColor = Color.FromArgb(99, 122, 110);
targetRow.Cells[3].BackgroundColor = Color.FromArgb(99, 122, 110);
table.EndUpdate();
}
private void tableStyleBtn_ItemClick(object sender, ItemClickEventArgs e)
{
document.BeginUpdate();
// Create a new table style
TableStyle tStyleMain = document.TableStyles.CreateNew();
// Specify style options
TableBorder insideHorizontalBorder = tStyleMain.TableBorders.InsideHorizontalBorder;
insideHorizontalBorder.LineStyle = TableBorderLineStyle.Single;
insideHorizontalBorder.LineColor = Color.White;
TableBorder insideVerticalBorder = tStyleMain.TableBorders.InsideVerticalBorder;
insideVerticalBorder.LineStyle = TableBorderLineStyle.Single;
insideVerticalBorder.LineColor = Color.White;
tStyleMain.CellBackgroundColor = Color.FromArgb(227, 238, 220);
tStyleMain.Name = "MyTableStyle";
// Add the style to the document collection
document.TableStyles.Add(tStyleMain);
// Create conditional styles (styles for specific table elements)
TableConditionalStyle myNewStyleForOddRows = tStyleMain.ConditionalStyleProperties.CreateConditionalStyle(ConditionalTableStyleFormattingTypes.OddRowBanding);
myNewStyleForOddRows.CellBackgroundColor = Color.FromArgb(196, 220, 182);
TableConditionalStyle myNewStyleForBottomRightCell = tStyleMain.ConditionalStyleProperties.CreateConditionalStyle(ConditionalTableStyleFormattingTypes.BottomRightCell);
myNewStyleForBottomRightCell.CellBackgroundColor = Color.FromArgb(188, 214, 201);
document.EndUpdate();
document.BeginUpdate();
// Apply a previously defined style to the table
document.Tables[0].Style = tStyleMain;
document.EndUpdate();
}
private void deleteCellBtn_ItemClick(object sender, ItemClickEventArgs e)
{
table.BeginUpdate();
// Delete a cell
table.Cell(1, 1).Delete();
// Delete a row
table.Rows[0].Delete();
table.EndUpdate();
}
private void deleteRowBtn_ItemClick(object sender, ItemClickEventArgs e)
{
table.BeginUpdate();
// Delete a row
table.Rows[0].Delete();
table.EndUpdate();
}
private void deleteColumnBtn_ItemClick(object sender, ItemClickEventArgs e)
{
// Call the declared method using ForEachRow method and the corresponding delegate
table.ForEachRow(new TableRowProcessorDelegate(DeleteCells));
}
// Declare a method that deletes the second cell in every table row
public static void DeleteCells(TableRow row, int i)
{
row.Cells[1].Delete();
}
private void rotateButtonItem1_ItemClick(object sender, ItemClickEventArgs e)
{
table.BeginUpdate();
table[2, 0].TextDirection = TextDirection.Upward;
table.EndUpdate();
}
}
}