0

我想知道是否有一种简单的方法可以对我的富文本框实施拼写检查?我听说有一种方法可以使用 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 未处理错误。

有任何想法吗?我不知道从这一点开始。我可以加载程序,但在未注释的代码行上出现错误。我试过关注演示,但我似乎看不出为什么演示代码有效,但我的代码拒绝发挥良好......我的代码与演示示例完全相同(据我所见),所以为什么当我尝试运行拼写检查器时,它现在是否正常工作并给我一个错误?

4

1 回答 1

3

它有点旧,但我个人使用过 NetSpell,它似乎很容易设置,只需将项目包含在您的 Visual Studio 解决方案中,它应该很好。

http://www.codeproject.com/Articles/5277/NetSpell-Spell-Checker-for-NET

于 2013-04-26T22:58:31.960 回答