2013-04-26 27 views
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是在代碼註釋掉行未處理的錯誤。

任何想法?從這一點我不知道該走到哪裏。我可以加載該程序,但是在未註釋的代碼行上出現錯誤。我試着按照演示,但我似乎無法看到爲什麼演示代碼的作品,但我拒絕演奏好...我的代碼是完全一樣的演示示例(從我所能看到的),所以爲什麼當我嘗試運行拼寫檢查程序時,它現在是否正在運行並給我一個錯誤?

+0

我想你會發現在這個線程的回答你的問題: http://stackoverflow.com/questions/453611/what-is-the-best-spell-checking-library- for-c – 2013-04-26 22:20:04

+0

@ s_qw23這個線程的哪一部分是你特指的? :o) – Toby 2013-04-26 22:21:11

+0

在這一個:「如果我可以添加一個獨立的拼寫檢查到我的應用程序」。如果它與您正在搜索的內容不匹配,我是sry:D認爲您正在搜索某個模塊或其他內容,但是如果您想自行編寫它,則可能不是正確的源代碼。 – 2013-04-26 22:24:59

回答

3

這是年紀大一點的,但我曾親自使用NetSpell這似乎是很容易設置,只需在您的Visual Studio解決方案的項目,它應該是好去。

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

+0

感謝您的鏈接。有關如何實現這一點的任何提示? – Toby 2013-04-26 23:15:46

+0

因爲演示看起來很有前途。 – Toby 2013-04-26 23:42:45

+0

下載它後,您應該能夠在Visual Studio中下拉項目,一旦編譯該項目,就可以在解決方案中引用該DLL。 一旦你有了參考資料,在我之前鏈接的頁面大約一半的位置,就有一個「使用庫」,它幾乎涵蓋了運行拼寫檢查的代碼。 – 2013-04-26 23:45:08

相關問題