-
Notifications
You must be signed in to change notification settings - Fork 0
/
RichTextEditForm.cs
81 lines (78 loc) · 3.25 KB
/
RichTextEditForm.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
using System;
using DevExpress.Spreadsheet;
using DevExpress.XtraRichEdit.API.Native;
namespace SpreadsheetRichText
{
public partial class RichTextEditForm : DevExpress.XtraEditors.XtraForm
{
private Cell cell;
public RichTextEditForm(Cell cell)
{
InitializeComponent();
this.cell = cell;
InitRichEditControl();
}
private void InitRichEditControl()
{
richEditControl1.BeginUpdate();
if (cell.HasRichText)
{
RichTextString richText = cell.GetRichText();
Document document = richEditControl1.Document;
foreach (RichTextRun run in richText.Runs)
{
DocumentRange range = document.InsertText(document.Range.End, run.Text);
CharacterProperties cp = document.BeginUpdateCharacters(range);
cp.Bold = run.Font.Bold;
cp.ForeColor = run.Font.Color;
cp.Italic = run.Font.Italic;
cp.FontName = run.Font.Name;
cp.FontSize = (float)run.Font.Size;
cp.Strikeout = run.Font.Strikethrough ? StrikeoutType.Single : StrikeoutType.None;
switch (run.Font.Script)
{
case ScriptType.Subscript:
cp.Subscript = true;
break;
case ScriptType.Superscript:
cp.Superscript = true;
break;
default:
cp.Subscript = false;
cp.Superscript = false;
break;
}
switch (run.Font.UnderlineType)
{
case DevExpress.Spreadsheet.UnderlineType.Single:
cp.Underline = DevExpress.XtraRichEdit.API.Native.UnderlineType.Single;
break;
case DevExpress.Spreadsheet.UnderlineType.Double:
cp.Underline = DevExpress.XtraRichEdit.API.Native.UnderlineType.Double;
break;
default:
cp.Underline = DevExpress.XtraRichEdit.API.Native.UnderlineType.None;
break;
}
document.EndUpdateCharacters(cp);
}
}
else
richEditControl1.Text = cell.DisplayText;
richEditControl1.EndUpdate();
}
private void OKButton_Click(object sender, EventArgs e)
{
CustomDocumentVisitor visitor = new CustomDocumentVisitor(richEditControl1.Document.Range.End.ToInt());
DocumentIterator iterator = new DocumentIterator(richEditControl1.Document, true);
while (iterator.MoveNext())
{
iterator.Current.Accept(visitor);
}
RichTextString richText = visitor.RichText;
cell.SetRichText(richText);
if (richEditControl1.Document.Paragraphs.Count > 1)
cell.Alignment.WrapText = true;
}
}
}