XtraSpellChecker: How to Enable Spell Checking

19 September 2007

In a previous post, you learned about the XtraSpellChecker component. Now let's dig deeper and see some samples to enable spell checking in your application.

Runtime Samples

The following examples will show you how to use the Check and CheckContainer methods in different ways. These methods allow you to check the spelling of various controls.

Check a TextBox

To check the text of a TextBox control use the following code. You can bind this method to just about any event such as a button click:

private void simpleButton1_Click(object sender, EventArgs e) {
    spellChecker1.Check(textBox1);
}

Check any text-aware control

The Check method can check text from any control. Just pass the text value to the Check method and you'll be returned the text processed by the spell-checker engine.

private void simpleButton1_Click(object sender, EventArgs e) {
    myTextControl.Text = spellChecker1.Check(myTextControl.Text);
}

Check all controls on a form

If you want to check all text-aware controls on a container then just call the CheckContainer method:

private void simpleButton1_Click(object sender, EventArgs e) {
    spellChecker1.CheckContainer(this);
}

Use a Hotkey like F7

One of the default hotkeys for Microsoft Office is F7 for spell checking. You can provide the same experience and familiarity for your users by binding the F7 key for your form to start spell checking. Below, the F7 key is bound to an XtraGrid Control:

private void gridControl1_EditorKeyDown(object sender, KeyEventArgs e) {
    if (e.KeyCode == Keys.F7 && e.Modifiers == Keys.None)
        DoCheck();
}

protected virtual void DoCheck() {
    spellChecker1.Check(GetActiveControl());
}

private Control GetActiveControl() {
    return gridControl1.FocusedView.IsEditing ? 
        gridControl1.FocusedView.ActiveEditor : ActiveControl;
}

Checking via the context menu

Right-clicking to check text is very popular as well. You can easily provide this for certain controls like a Memo control by calling the SpellChecker.SetShowSpellCheckMenu method:

private void MemoEditForm_Load(object sender, EventArgs e) {
    spellChecker1.SetShowSpellCheckMenu(memoEdit1, true);
}

You now have the "Check Spelling" menu item added to the bottom of the control's context menu:

The "Check Spelling" menu item

Viola, your text-aware controls can now easily be spell checked!

You can try all the samples above for yourself. Just download the following file and open in Visual Studio 2005: SpellCheckerExample.Zip

Are you curious about anything else with the XtraSpellChecker? Just drop me a note or comment here. Thanks.

7 comment(s)
Alex Danvy

More than ever, this spell check component remind me the missing RTF editor from DevExpress ;-)

What about "live" or spell check as you type feature ?

20 September, 2007
Martin Paternoster

It would be interesting to be able to obtain this control as a separate product.

At this point, it is only available as part of the DXperience subscriptions.

20 September, 2007
Mehul Harry (DevExpress)

Hi Martin,

Thanks for the suggestion. We'll definitely consider it.

20 September, 2007
Mehul Harry (DevExpress)

Hi Alex,

The Rich editor is coming soon. :-)

I'll have an update for you soon on the spell check as you type feature. In the meantime you can see the requests and their status here:

www.devexpress.com/.../SearchResults.aspx

Thanks.

20 September, 2007
Windows Forms

Did you know that the XtraSpellChecker Suite can check spelling as you type? Just like in MS Word or

24 September, 2007
Mehul Harry (DevExpress)

Hi Alex,

Alan has created a post about spell checking as you type here:

community.devexpress.com/.../xtraspellchecker-check-spelling-as-you-type.aspx

Thanks.

24 September, 2007
how to enable word verification

Pingback from  how to enable word verification

30 May, 2008

Please login or register to post comments.