This repository has been archived by the owner on Oct 24, 2023. It is now read-only.
/
Form1.cs
78 lines (69 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
using DevExpress.XtraBars;
using DevExpress.XtraSpellChecker;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace SpellCheckerMenuExample
{
public partial class Form1 : Form
{
PopupMenu popupMenu1 = new PopupMenu();
BarManager barManager1 = new BarManager();
public Form1()
{
InitializeComponent();
spellChecker1.PrepareSuggestions += spellChecker1_PrepareSuggestions;
barManager1.Form = this;
}
private void Form1_Load(object sender, EventArgs e)
{
spellChecker1.SpellCheckMode = SpellCheckMode.AsYouType;
spellChecker1.ParentContainer = this;
spellChecker1.CheckAsYouTypeOptions.CheckControlsInParentContainer = true;
popupMenu1.Manager = barManager1;
barManager1.QueryShowPopupMenu += barManager1_QueryShowPopupMenu;
// Add spelling menu to the standard controls.
barManager1.SetPopupContextMenu(textBox1, popupMenu1);
barManager1.SetPopupContextMenu(richTextBox1, popupMenu1);
}
private void barManager1_QueryShowPopupMenu(object sender, QueryShowPopupMenuEventArgs e)
{
Point position = e.Control.PointToClient(e.Position);
DevExpress.XtraSpellChecker.Rules.SpellCheckErrorBase error = spellChecker1.CalcError(position);
e.Cancel = error == null;
List<SpellCheckerCommand> commands = spellChecker1.GetCommandsByError(error);
if (commands != null)
{
popupMenu1.ItemLinks.Clear();
foreach (SpellCheckerCommand command in commands)
{
BarButtonItem item = new BarButtonItem(barManager1, command.Caption);
item.Enabled = command.Enabled;
item.Tag = command;
item.ItemClick += new ItemClickEventHandler(OnPopupMenuItemClick);
popupMenu1.ItemLinks.Add(item);
}
BarButtonItem itemShowSpellingForm = new BarButtonItem(barManager1, "Show Spelling Form");
itemShowSpellingForm.ItemClick += OnPopupMenuShowSpellingForm_ItemClick;
popupMenu1.ItemLinks.Add(itemShowSpellingForm);
}
}
void OnPopupMenuItemClick(object sender, ItemClickEventArgs e)
{
(e.Item.Tag as SpellCheckerCommand).DoCommand();
}
void OnPopupMenuShowSpellingForm_ItemClick(object sender, ItemClickEventArgs e)
{
spellChecker1.Check(this.ActiveControl);
}
#region #preparesuggestions_event
void spellChecker1_PrepareSuggestions(object sender, PrepareSuggestionsEventArgs e)
{
string pattern = "(De|de)[a-z]+x[a-z]*s+";
System.Text.RegularExpressions.Regex rgx = new System.Text.RegularExpressions.Regex(pattern);
if (rgx.IsMatch(e.Word)) e.Suggestions.Insert(0, new SuggestionBase("DevExpress", 0));
}
#endregion #preparesuggestions_event
}
}