-
Notifications
You must be signed in to change notification settings - Fork 1
/
Form1.cs
89 lines (79 loc) · 3.08 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
using System;
using System.IO;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
#region #usings
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.Services;
#endregion #usings
namespace Expander
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
richEditControl1.CreateNewDocument();
SetAutoCorrectOptions();
richEditControl1.Document.AppendText(@"This sample expander uses Mary Morken's 2007 list of abbreviations for medical transcriptions, containing 13420 entries.
The list has been downloaded from http://www.mtdaily.com/abbvs.txt. To indicate the beginning of the list, the line containing the 'START' string is added.");
#region #autocorrectservice
IAutoCorrectService svc = richEditControl1.GetService<IAutoCorrectService>();
if (svc != null)
svc.SetReplaceTable(LoadAbbrevs("abbvs.txt"));
#endregion #autocorrectservice
}
private void SetAutoCorrectOptions()
{
#region #options
AutoCorrectOptions correctionOptions = richEditControl1.Options.AutoCorrect;
correctionOptions.CorrectTwoInitialCapitals = true;
correctionOptions.DetectUrls = false;
correctionOptions.ReplaceTextAsYouType = true;
correctionOptions.UseSpellCheckerSuggestions = true;
#endregion #options
}
#region #setreplacetable
private AutoCorrectReplaceInfoCollection LoadAbbrevs(string path)
{
AutoCorrectReplaceInfoCollection coll = new AutoCorrectReplaceInfoCollection();
string aLine = "";
AutoCorrectReplaceInfo acrInfoIm = new AutoCorrectReplaceInfo(":-)", CreateImageFromResx("smile.png"));
coll.Add(acrInfoIm);
if (File.Exists(path))
{
StreamReader sr = new StreamReader(path);
while (!(sr.EndOfStream))
{
aLine = sr.ReadLine();
if (aLine != "START") continue;
while (!(sr.EndOfStream))
{
aLine = sr.ReadLine();
aLine = aLine.Trim();
string[] words = aLine.Split('=');
if (words.Length == 2)
{
AutoCorrectReplaceInfo acrInfo = new AutoCorrectReplaceInfo(words[0], words[1]);
coll.Add(acrInfo);
}
}
}
sr.Close();
}
return coll;
}
#endregion #setreplacetable
private Image CreateImageFromResx(string name)
{
Image im;
Assembly assembly = Assembly.GetExecutingAssembly();
using (Stream stream = assembly.GetManifestResourceStream("Expander.Images." + name))
{
im = Image.FromStream(stream);
}
return im;
}
}
}