【发布时间】:2013-04-21 04:42:04
【问题描述】:
我想知道是否有一种简单的方法可以对我的富文本框实施拼写检查?我听说有一种方法可以使用 MS Word 的拼写检查,但我想知道是否可以在我的应用程序中添加独立的拼写检查。如果有人可以为我提供有关如何执行此操作的教程(视频或网页或示例或任何内容),那么我真的会 欣赏它。
--编辑--
根据我收到的答案,我对我的代码实施了拼写检查,现在如下:
private NetSpell.SpellChecker.Spelling spelling;
private NetSpell.SpellChecker.Dictionary.WordDictionary wordDictionary;
internal System.Windows.Forms.Button spellButton;
internal System.Windows.Forms.RichTextBox demoRichText;
private System.ComponentModel.IContainer components2;
internal System.Windows.Forms.RichTextBox Document;
internal NetSpell.SpellChecker.Spelling SpellChecker;
private System.ComponentModel.IContainer components1;
internal NetSpell.SpellChecker.Dictionary.WordDictionary WordDictionary;
...
private void toolStripButton1_Click(object sender, EventArgs e)
{
try
{
this.spelling.Text = this.richTextBoxPrintCtrl1.Text; // I get an error on this line.
this.spelling.SpellCheck();
}
catch
{
MessageBox.Show("Error loading Spell Checker. Please reload application and try again.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void spelling_DeletedWord(object sender, NetSpell.SpellChecker.SpellingEventArgs e)
{
int start = this.richTextBoxPrintCtrl1.SelectionStart;
int length = this.richTextBoxPrintCtrl1.SelectionLength;
this.richTextBoxPrintCtrl1.Select(e.TextIndex, e.Word.Length);
this.richTextBoxPrintCtrl1.SelectedText = "";
if (start > this.richTextBoxPrintCtrl1.Text.Length)
start = this.richTextBoxPrintCtrl1.Text.Length;
if ((start + length) > this.richTextBoxPrintCtrl1.Text.Length)
length = 0;
this.richTextBoxPrintCtrl1.Select(start, length);
}
private void spelling_ReplacedWord(object sender, NetSpell.SpellChecker.ReplaceWordEventArgs e)
{
int start = this.richTextBoxPrintCtrl1.SelectionStart;
int length = this.richTextBoxPrintCtrl1.SelectionLength;
this.richTextBoxPrintCtrl1.Select(e.TextIndex, e.Word.Length);
this.richTextBoxPrintCtrl1.SelectedText = e.ReplacementWord;
if (start > this.richTextBoxPrintCtrl1.Text.Length)
start = this.richTextBoxPrintCtrl1.Text.Length;
if ((start + length) > this.richTextBoxPrintCtrl1.Text.Length)
length = 0;
this.richTextBoxPrintCtrl1.Select(start, length);
}
private void spelling_EndOfText(object sender, System.EventArgs e)
{
Console.WriteLine("EndOfText");
}
但是,当我尝试加载检查器时,在代码中未注释的行上出现 NullReferenceExeption 未处理错误。
有什么想法吗?我不知道从这一点开始。我可以加载程序,但在未注释的代码行上出现错误。我试过关注演示,但我似乎看不出为什么演示代码有效,但我的代码拒绝发挥良好......我的代码与演示示例完全相同(据我所见),所以为什么当我尝试运行拼写检查器时,它现在是否正常工作并给我一个错误?
【问题讨论】:
-
我想你会在这个帖子中找到你的问题的答案:stackoverflow.com/questions/453611/…
-
@s_qw23 您具体指的是该线程的哪一部分? :o)
-
在这个:“如果我可以在我的应用程序中添加一个独立的拼写检查”。如果它与您正在搜索的内容不匹配,我很抱歉:D 以为您正在搜索模块或其他东西,但如果您想自己编写它可能不是正确的来源。
-
@s_qw23 你知道如何在我的应用程序中实现 NHunspell 吗?我不知道从哪里开始.. :)
-
或许以the documentation开头。
标签: c# visual-studio .net-4.0 richtextbox