in
Forums
Blogs
Files
Devexpress.Com
ClientCenter
Support Center
DevExpress Channel

Windows Forms

September 2007 - Posts

  • XtraSpellChecker: Check Spelling as You Type

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

    Enabling this feature is a breeze, just set one property and call one method:

    Set the SpellCheckMode property to AsYouType:

    spellChecker1.SpellCheckMode = SpellCheckMode.AsYouType;
    

    Then call the SpellChecker.Check method, and you're set:

    spellChecker1.Check(memoEdit1);
    

    After enabling the "check as you type" feature, red curves are displayed under misspelled words. Words are underlined to show that the spell checker doesn't recognize them.

    Check spelling as you type

     

    The appearance of the red curves are fully customizable. If you prefer Blue then set the SpellChecker.CheckAsYouTypeOptions.Color property:

    Set the CheckAsYouTypeOptions property

    To correct a misspelled word just right-click on the misspelled word and you'll get a list of suggested words from the dictionary:

    Blue lines

    Parts [1] and [2] of this series showed the XtraSpellChecker's other capabilities. In a future post, you'll see how different dictionaries can be used to make XtraSpellChecker conform to your needs.

    Are you curious about other XtraSpellChecker features?

    Which features are your favorites?

    Please leave a comment below and let me know. Thanks!

  • XtraSpellChecker: How to Enable Spell Checking

    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.

  • XtraSpellChecker: A simple but powerful spell checker for WinForms applications

    You can easily provide spell checking capabilities to your WinForms applications with XtraSpellChecker.

    image 

    Compatible Controls

    The Spell Checker can check the spelling of almost any control that has a Text property. Some examples of supported controls:

    • System.Windows.Forms.TextBox
    • DevExpress.XtraEditors.TextEdit
    • DevExpress.XtraEditors.MemoEdit
    • System.Windows.Forms.RichTextBox (Next Release, 2007 vol 3)

    The XtraSpellChecker can check with our WinForms grids (e.g. XtraGrid, XtraVerticalGrid, etc.) as well since they contain TextEdit and MemoEdit editors for their cells.

    You can also check any arbitrary text by passing it to the Check method as a parameter.

    Components To Use

    The main component, which provides all spell checking abilities, is the SpellChecker. The clip_image001SpellChecker is located in the “DX: Win.v7.2” tab in the Visual Studio toolbox. You can also create it at runtime:

    using DevExpress.XtraSpellChecker;
    
    SpellChecker spellChecker1 = new SpellChecker();
    

    You can now set some it's properties like the default for Culture property. This specifies culture settings (the symbols encoding, language and phonetic specifics):

    spellChecker1.Culture = new System.Globalization.CultureInfo("en-US");
    

    Please note that if you use several SpellChecker components and one dictionary, then a clip_image002SharedDictionaryStorage component is required.

    Enable Spell Checking

    The SpellChecker component provides two methods to check the spelling for controls: Check() and CheckContainer().

    The following code demonstrates how to pass a text to the Check method:

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

    The Dictionaries

    The SpellChecker component uses special spell checking algorithms. Every algorithm requires a dictionary, which provides the list of words and/or rules to generate this list. To enable spell checking in your application you need to define at least one dictionary.

    First choose which dictionary best meets your requirements. The XtraSpellChecker suite supports four basic dictionary types.

    • Simple
    • ISpell
    • Open Office
    • Custom

    Dictionaries can be defined both at design and runtime. For example, at runtime you can create an ISpell dictionary:

        iSpellDictionary = new SpellCheckerISpellDictionary();
       iSpellDictionary.Culture = new CultureInfo("en-US");
       iSpellDictionary.AlphabetPath = @"\Dicts\Dicts\ISpell\EnglishAlphabet.txt";
       iSpellDictionary.DictionaryPath = @"\Dicts\Dicts\ISpell\american.xlg";
       iSpellDictionary.GrammarPath = @"\Dicts\Dicts\ISpell\english.aff";
    

    You'll see each of these dictionaries described in more detail in an upcoming post.

    Download and try the XtraSpellChecker today. The XtraSpellChecker Suite is part of the DXperience Professional and Enterprise Suites. Currently, the XtraSpellChecker Suite is for Windows Forms only. However, an ASP .NET version is being developed.

    Are you using the XtraSpellChecker in your apps? I'd love to hear your stories with this amazing little control.

Copyright © 1998-2008 Developer Express Inc.
ALL RIGHTS RESERVED