Step 4: Provide Long Document Spell Checking (Middle Panel)
Simply double-click the button on the middle panel and add the following code to the Button1_Click event:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' this will check the whole window, displaying the
' spelling dialog when a bad word is found and
' correcting words as needed
C1Spell2.CheckControl(TextBox4)
' when it is done, give the user some feedback
If C1Spell2.BadWordCount > 0 Then
MessageBox.Show("Done spell checking. " & C1Spell2.BadWordCount & " typing errors.")
Else
MessageBox.Show("Done spell checking. No spelling errors.")
End If
End Sub
• C#
private void button1_Click(object sender, EventArgs e)
{
// this will check the whole window, displaying the
// spelling dialog when a bad word is found and
// correcting words as needed
c1Spell2.CheckControl(TextBox4);
// when it is done, give the user some feedback
if ( c1Spell2.BadWordCount > 0 )
MessageBox.Show("Done spell checking. " + c1Spell2.BadWordCount + " typing errors.")
else
MessageBox.Show("Done spell checking. No spelling errors.");
}
All it takes to spell check the window is a single call to the CheckControl method. We also show a message box after we're done spell checking, but this is optional.
If you think you will be spell checking really long documents (over 200K, say), you may also want to handle the C1Spell2_Checking event. This will fire every second while spell checking a long document so you can display a progress bar or cancel the spell-checking process.
That's it for the middle pane on our demo. Save the project and run it again. Type some text into the middle panel textbox and click Spell Check. If you make any mistakes, you will see a dialog box containing suggestions.
|