You can check spelling in controls with a modal dialog box that does not allow the user to proceed until the check is complete. The CheckControlAsync method checks the spelling in controls that implement the ISpellCheckableEditor interface. The Microsoft TextBox and the C1RichTextBox controls implement this interface out of the box. You can create your own classes to provide wrappers for other controls to allow spelling to be checked in them.
The code below illustrates this mode:
C# |
Copy Code
|
---|---|
// Show modal dialog to check spelling private void Button2_Click(object sender, RoutedEventArgs e) { // Hook up event hander c1SpellChecker1.CheckControlCompleted += c1SpellChecker1_CheckControlCompleted; // Check spelling in a textbox c1SpellChecker1.CheckControlAsync(textBox1); // Unhook the event hander c1SpellChecker1.CheckControlCompleted += c1SpellChecker1_CheckControlCompleted; } void c1SpellChecker1_CheckControlCompleted(object sender, CheckControlCompletedEventArgs e) { Debug.WriteLine("CheckControlCompleted: {0} errors found", e.ErrorCount); if (e.Cancelled) WriteLine("\t(cancelled...)"); } |
This code shows a modal dialog box and highlights each spelling error, providing suggestions and allowing the user to fix or ignore each error. When the process is completed, the CheckControlCompleted event fires and provides feedback to the user.