I am trying to use NetSpell to spellcheck a richtextbox. Right now it finds incorrectly spelled words but when I select a word to replace the incorrectly spelled word with it doesn't do anything. What am I doing wrong?
This is the code I have right now:
private void checkSpellingToolStripMenuItem_Click(object sender, EventArgs e)
{
this.spelling.Text = this.richTextBox1.Text;
this.spelling.SpellCheck();
}
private void spelling_DeletedWord(object sender, NetSpell.SpellChecker.SpellingEventArgs e)
{
int start = this.richTextBox1.SelectionStart;
int length = this.richTextBox1.SelectionLength;
this.richTextBox1.Select(e.TextIndex, e.Word.Length);
this.richTextBox1.SelectedText = "";
if (start > this.richTextBox1.Text.Length)
start = this.richTextBox1.Text.Length;
if ((start + length) > this.richTextBox1.Text.Length)
length = 0;
this.richTextBox1.Select(start, length);
}
private void spelling_ReplacedWord(object sender, NetSpell.SpellChecker.ReplaceWordEventArgs e)
{
int start = this.richTextBox1.SelectionStart;
int length = this.richTextBox1.SelectionLength;
this.richTextBox1.Select(e.TextIndex, e.Word.Length);
this.richTextBox1.SelectedText = e.ReplacementWord;
if (start > this.richTextBox1.Text.Length)
start = this.richTextBox1.Text.Length;
if ((start + length) > this.richTextBox1.Text.Length)
length = 0;
this.richTextBox1.Select(start, length);
}
private void spelling_EndOfText(object sender, System.EventArgs e)
{
Console.WriteLine("EndOfText");
}

1 answers
Are you sure that you've wired up those three eventhandlers to their respective events?
If you've added the eventhandler skeletons from the Properties Box they should be wired up automatically but not if you've just copied and pasted the specimen code.
I'm not familiar with NetSpell but I'd guess from the context that to wire up the events would need the following code:
this.spelling.DeletedWord += spelling_DeletedWord;
this.spelling.ReplacedWord += spelling_ReplacedWord;
this.spelling.EndOfText += spelling_EndOfText;
Also, if it's a Windows Forms application, the last handler should be:
private void spelling_EndOfText(object sender, System.EventArgs e)
{
MessageBox.Show("EndOfText");
}
answered 2 years ago by:
17279
Thank you!
answered 2 years ago by:
51
This post was imported from csharpfriends, if you have a similiar question please ask it again.
All previous members have been migrated, hope you enjoy the new platform!