Editor for WinForms | ComponentOne
Creating an XHTML Editor in Code / The ToolStripMain class / Spell-Checking Commands
In This Topic
    Spell-Checking Commands
    In This Topic

    The C1Editor implements spell-checking with a SpellChecker property that allows you to connect it to a C1SpellChecker component.

    The C1SpellChecker is a separate, stand-alone component that can be used to spell-check many types of controls including TextBox, RichTextBox, WebBrowser, and of course the C1Editor. The C1SpellChecker includes spelling dictionaries for over 20 languages, and it includes a dictionary editor that allows you to create your own custom dictionaries.

    The C1Editor supports as-you-type spell checking (with red wavy lines under misspelled words and suggestions in context menus) as well as a dialog-based spell checking that highlights each misspelled word and allows the user to correct each one from the spell dialog.

    The ToolStripMain class exposes as-you-type spell-checking as follows:

    To write code in C#

    C#
    Copy Code
    void ShowSpellingErrors_Click(object sender, EventArgs e)
    {
        if (SpellChecker != null)
        {
            bool show = !_btnShowErrors.Checked;
            _btnShowErrors.Checked = show;
            SpellChecker.SetActiveSpellChecking(
                Editor, 
                Editor.GetActiveXInstance(), 
                show);
        }
    }
    

    The core of the method is a call to the C1SpellChecker's SetActiveSpellChecking method, which turns the as-you-type spell checking on or off for the specified control.

    The ToolStripMain class exposes modal spell-checking as follows:

    To write code in C#

    C#
    Copy Code
    void Spell_Click(object sender, EventArgs e)
    {
        if (SpellChecker != null)
        {
            SpellChecker.CheckControl(
                Editor, 
                Editor.GetActiveXInstance());
        }
    }
    

    The core of the method is a call to the C1SpellChecker's CheckControl method, which performs the dialog-based spell-checking for the specified control.