syncfusion-winforms-spell-checker
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseImplementing Syncfusion Windows Forms SpellChecker
实现Syncfusion Windows Forms拼写检查
The SpellCheckerAdv control provides Microsoft Office-style spell checking capabilities for Windows Forms text controls. This skill guides you through installation, control attachment, dictionary configuration, context menu integration, and customization options.
SpellCheckerAdv控件为Windows Forms文本控件提供了Microsoft Office风格的拼写检查功能。本技能将指导你完成安装、控件绑定、词典配置、右键菜单集成以及自定义选项设置。
When to Use This Skill
何时使用本技能
Use this skill when you need to:
- Add spell checking to RichTextBox or TextBox controls
- Configure dictionary sources (built-in English or custom dictionaries)
- Set up context menu-driven spell checking
- Customize ignore rules for special content (emails, URLs, numbers)
- Retrieve spelling suggestions and alternatives
- Support multiple languages via different dictionary formats
当你需要完成以下操作时使用本技能:
- 为RichTextBox或TextBox控件添加拼写检查
- 配置词典源(内置英语词典或自定义词典)
- 实现右键菜单驱动的拼写检查
- 为特殊内容(邮箱、URL、数字)自定义忽略规则
- 获取拼写建议和替代词
- 通过不同的词典格式支持多语言
Documentation Navigation
文档导航
Getting Started
入门指南
📄 Read: references/getting-started.md
- Installation and assembly references
- Adding control via designer or code
- Configuring SpellCheckerAdv with text controls
- Invoking spell check operations
- Basic implementation patterns
📄 阅读: references/getting-started.md
- 安装和程序集引用
- 通过设计器或代码添加控件
- 为文本控件配置SpellCheckerAdv
- 调用拼写检查操作
- 基础实现模式
Dictionary Configuration
词典配置
📄 Read: references/dictionary-setup.md
- Setting up default English dictionary
- Adding Hunspell dictionaries for multiple languages
- Adding Ispell dictionaries
- Adding OpenOffice dictionaries
- Switching cultures at runtime
- Custom dictionary support
📄 阅读: references/dictionary-setup.md
- 配置默认英语词典
- 为多语言添加Hunspell词典
- 添加Ispell词典
- 添加OpenOffice词典
- 运行时切换区域文化
- 自定义词典支持
Context Menu Integration
右键菜单集成
📄 Read: references/context-menu-integration.md
- Implementing ISpellCheckerAdvEditorTools interface
- Creating TextBoxSpellEditor wrapper class
- Setting up runtime context menus
- User-driven spell checking workflow
- Adding to dictionary from context menu
📄 阅读: references/context-menu-integration.md
- 实现ISpellCheckerAdvEditorTools接口
- 创建TextBoxSpellEditor包装类
- 配置运行时右键菜单
- 用户驱动的拼写检查工作流
- 从右键菜单添加单词到词典
Customization & Suggestions
自定义与建议功能
📄 Read: references/customization-suggestions.md
- Ignore options (emails, URLs, mixed case, special symbols)
- Retrieving suggestion lists
- Phonetic word alternatives
- Anagram suggestions
- Custom word management
📄 阅读: references/customization-suggestions.md
- 忽略选项(邮箱、URL、大小写混合、特殊符号)
- 获取建议列表
- 语音相似的单词替代词
- 变位词建议
- 自定义单词管理
Quick Start Example
快速入门示例
Basic Spell Check Setup:
csharp
using Syncfusion.Windows.Forms.Tools;
// 1. Create SpellCheckerAdv control
SpellCheckerAdv spellCheckerAdv = new SpellCheckerAdv();
// 2. Set dictionary path
spellCheckerAdv.DictionaryPath = "Syncfusion_en_us.dic";
// 3. Attach to RichTextBox and trigger spell check
RichTextBox richTextBox = new RichTextBox();
spellCheckerAdv.SpellCheck(new SpellCheckerAdvEditorWrapper(richTextBox));Context Menu Spell Checking:
csharp
// Implement ISpellCheckerAdvEditorTools
class TextBoxSpellEditor : ISpellCheckerAdvEditorTools
{
private TextBoxBase textBox;
public TextBoxSpellEditor(Control control)
{
Control = control;
}
public Control Control
{
get { return textBox; }
set { textBox = value as TextBoxBase; }
}
public string Text
{
get { return textBox.Text; }
set { textBox.Text = value; }
}
public string CurrentWord { get; set; }
public void SelectText(int start, int length)
{
textBox.Select(start, length);
}
}
// Enable context menu spell checking
TextBoxSpellEditor editor = new TextBoxSpellEditor(richTextBox);
spellCheckerAdv.PerformSpellCheckUsingContextMenu(editor);基础拼写检查设置:
csharp
using Syncfusion.Windows.Forms.Tools;
// 1. Create SpellCheckerAdv control
SpellCheckerAdv spellCheckerAdv = new SpellCheckerAdv();
// 2. Set dictionary path
spellCheckerAdv.DictionaryPath = "Syncfusion_en_us.dic";
// 3. Attach to RichTextBox and trigger spell check
RichTextBox richTextBox = new RichTextBox();
spellCheckerAdv.SpellCheck(new SpellCheckerAdvEditorWrapper(richTextBox));右键菜单拼写检查:
csharp
// Implement ISpellCheckerAdvEditorTools
class TextBoxSpellEditor : ISpellCheckerAdvEditorTools
{
private TextBoxBase textBox;
public TextBoxSpellEditor(Control control)
{
Control = control;
}
public Control Control
{
get { return textBox; }
set { textBox = value as TextBoxBase; }
}
public string Text
{
get { return textBox.Text; }
set { textBox.Text = value; }
}
public string CurrentWord { get; set; }
public void SelectText(int start, int length)
{
textBox.Select(start, length);
}
}
// Enable context menu spell checking
TextBoxSpellEditor editor = new TextBoxSpellEditor(richTextBox);
spellCheckerAdv.PerformSpellCheckUsingContextMenu(editor);Common Implementation Patterns
常见实现模式
Pattern 1: Dialog-Based Spell Checking
模式1:基于对话框的拼写检查
User clicks a "Spell Check" button → SpellCheckerAdv dialog opens → User reviews and corrects misspelled words → Dialog closes.
csharp
private void buttonSpellCheck_Click(object sender, EventArgs e)
{
spellCheckerAdv.SpellCheck(new SpellCheckerAdvEditorWrapper(richTextBox));
}用户点击“拼写检查”按钮 → SpellCheckerAdv对话框打开 → 用户查看并纠正拼写错误的单词 → 对话框关闭。
csharp
private void buttonSpellCheck_Click(object sender, EventArgs e)
{
spellCheckerAdv.SpellCheck(new SpellCheckerAdvEditorWrapper(richTextBox));
}Pattern 2: Real-Time Context Menu
模式2:实时右键菜单
User right-clicks misspelled word → Context menu appears with suggestions → User selects correction or adds to dictionary.
csharp
TextBoxSpellEditor editor = new TextBoxSpellEditor(richTextBox);
spellCheckerAdv.PerformSpellCheckUsingContextMenu(editor);用户右键点击拼写错误的单词 → 出现带建议的右键菜单 → 用户选择更正项或将单词添加到词典。
csharp
TextBoxSpellEditor editor = new TextBoxSpellEditor(richTextBox);
spellCheckerAdv.PerformSpellCheckUsingContextMenu(editor);Pattern 3: Multi-Language Support
模式3:多语言支持
Configure multiple dictionary cultures and switch at runtime based on user preference or content language.
csharp
SpellCheckerAdv spellChecker = new SpellCheckerAdv();
spellChecker.Dictionaries = new DictionaryCollection();
// Add English dictionary
spellChecker.Dictionaries.Add(new HunspellDictionary()
{
Culture = new CultureInfo("en-US"),
DictionaryPath = @"en-US.dic",
GrammarPath = @"en-US.aff"
});
// Add French dictionary
spellChecker.Dictionaries.Add(new HunspellDictionary()
{
Culture = new CultureInfo("fr-FR"),
DictionaryPath = @"fr-FR.dic",
GrammarPath = @"fr-FR.aff"
});
// Switch to French at runtime
spellChecker.Culture = new CultureInfo("fr-FR");配置多个词典区域文化,根据用户偏好或内容语言在运行时切换。
csharp
SpellCheckerAdv spellChecker = new SpellCheckerAdv();
spellChecker.Dictionaries = new DictionaryCollection();
// Add English dictionary
spellChecker.Dictionaries.Add(new HunspellDictionary()
{
Culture = new CultureInfo("en-US"),
DictionaryPath = @"en-US.dic",
GrammarPath = @"en-US.aff"
});
// Add French dictionary
spellChecker.Dictionaries.Add(new HunspellDictionary()
{
Culture = new CultureInfo("fr-FR"),
DictionaryPath = @"fr-FR.dic",
GrammarPath = @"fr-FR.aff"
});
// Switch to French at runtime
spellChecker.Culture = new CultureInfo("fr-FR");Key Props & Methods
核心属性与方法
| Element | Purpose | When to Use |
|---|---|---|
| Set built-in dictionary location | Simple English spell checking |
| Add custom dictionaries (Hunspell, Ispell, OpenOffice) | Multi-language support |
| Set active spell-check language | Language switching |
| Trigger spell-check dialog | User-initiated spell checking |
| Enable context menu suggestions | Real-time spell checking |
| Retrieve correction suggestions | Programmatic spell checking |
| Skip special content types | Customized spell checking |
| 元素 | 用途 | 使用场景 |
|---|---|---|
| 设置内置词典的位置 | 简单的英语拼写检查 |
| 添加自定义词典(Hunspell、Ispell、OpenOffice) | 多语言支持 |
| 设置激活的拼写检查语言 | 语言切换 |
| 触发拼写检查对话框 | 用户主动发起拼写检查 |
| 启用右键菜单建议 | 实时拼写检查 |
| 获取更正建议 | 程序化拼写检查 |
| 跳过特殊内容类型 | 自定义拼写检查 |
Common Use Cases
常见使用场景
- Email Client: Right-click spell checking with custom dictionaries
- Document Editor: Multi-language spell checking with context menu
- Form Validator: Check user input before submission
- Content Management: Ignore URLs and email addresses in content
- Multilingual App: Switch spell-check language based on UI culture
- 邮件客户端: 带自定义词典的右键拼写检查
- 文档编辑器: 带右键菜单的多语言拼写检查
- 表单校验器: 提交前检查用户输入
- 内容管理: 忽略内容中的URL和邮箱地址
- 多语言应用: 根据UI文化切换拼写检查语言