# AutoCorrect Using TX Text Control and TX Spell .NET

> TX Spell .NET ranks the correct suggestion at position one or two in over 97 percent of cases by evaluating keyboard key distance and other factors. The KeyPress event triggers replacement on delimiters, and repeated corrections on the same word are automatically suppressed.

- **Author:** Bjoern Meyer
- **Published:** 2017-08-17
- **Modified:** 2026-07-17
- **Description:** TX Spell .NET ranks the correct suggestion at position one or two in over 97 percent of cases by evaluating keyboard key distance and other factors. The KeyPress event triggers replacement on delimiters, and repeated corrections on the same word are automatically suppressed.
- **3 min read** (433 words)
- **Tags:**
  - Sample
  - TX Spell .NET
  - Windows Forms
- **Web URL:** https://www.textcontrol.com/blog/2017/08/17/autocorrect-using-tx-text-control-and-tx-spell-net/
- **LLMs URL:** https://www.textcontrol.com/blog/2017/08/17/autocorrect-using-tx-text-control-and-tx-spell-net/llms.txt
- **LLMs-Full URL:** https://www.textcontrol.com/blog/2017/08/17/autocorrect-using-tx-text-control-and-tx-spell-net/llms-full.txt

---

AutoCorrect can be very annoying on a smartphone - we all know this. But if you are used to it and then start typing on a computer keyboard, you are missing this time saving feature.

![AutoCorrect using TX Text Control and TX Spell .NET](https://s1-www.textcontrol.com/assets/dist/blog/2017/08/17/a/assets/animation_autocorrect.webp "AutoCorrect using TX Text Control and TX Spell .NET")TX Spell .NET provides a very powerful spell checking and suggestion engine that can be used to implement AutoCorrect with a few lines of code:

```
string sLastStoredWordText;

private void textControl1_KeyPress(object sender, KeyPressEventArgs e)
{
    // delimiter array 
    char[] cDelimiters = new char[] { ',','.','\r','\t',' ' };

    // check, if a delimiter has been pressed and if
    // misspelled words have been found
    if (!cDelimiters.Contains(e.KeyChar) ||
        textControl1.MisspelledWords == null ||
        textControl1.MisspelledWords.Count == 0)
        return;

    int iTextPosition = textControl1.InputPosition.TextPosition;

    // find a misspelled word at the input position
    MisspelledWord mwLastWord = 
        textControl1.MisspelledWords.GetItem(iTextPosition);

    // if the found word is not at the input position
    // store the last word and return
    if (mwLastWord.Start + mwLastWord.Length != iTextPosition + 1)
    {
        sLastStoredWordText = mwLastWord.Text; return;
    }

    // if the found word is the last word, store it and return
    // this prevents an auto replacement for intentionally wrong words
    if (mwLastWord.Text == sLastStoredWordText)
    {
        sLastStoredWordText = mwLastWord.Text; return;
    }

    // store the last word
    sLastStoredWordText = mwLastWord.Text;

    // create the suggestions, we only need the first
    txSpellChecker1.CreateSuggestions(mwLastWord.Text, 1);

    // if suggestions are found, replace the word with the suggestion
    if (txSpellChecker1.Suggestions.Count > 0)
    {
        e.Handled = true;

        string sSuggestion = txSpellChecker1.Suggestions[0].Text + " ";
        textControl1.MisspelledWords.Remove(mwLastWord, sSuggestion);
        textControl1.Select(mwLastWord.Start + sSuggestion.Length, 0);
    }
}
```

Based on the analysis of thousands of test documents, the expected suggestion is ranked at position 1 or 2 in more than 97% of all cases. The algorithm includes the measurement of the distance between the keys on the currently used keyboard. Many different factors are evaluated and rated to create the accurate list of suggestions.

Essentially, the KeyPress event is used to trap keystrokes when a delimiter such as a space, a '.' or a ',' is typed in. Afer that, the misspelled word at the current input position is checked and replaced with the first suggestion of the TX Spell .NET suggestion engine.

This implementation checks also, if you intentionally typed a word incorrect. The second time you "correct" the correction, AutoCorrect is not applied to the same word again.

![AutoCorrect using TX Text Control and TX Spell .NET](https://s1-www.textcontrol.com/assets/dist/blog/2017/08/17/a/assets/animation_autocorrect2.webp "AutoCorrect using TX Text Control and TX Spell .NET")Happy coding!

---

## About Bjoern Meyer

As CEO, Bjoern is the visionary behind our strategic direction and business development, bridging the gap between our customers and engineering teams. His deep passion for coding and web technologies drives the creation of innovative products. If you're at a tech conference, be sure to stop by our booth - you'll most likely meet Bjoern in person. With an advanced graduate degree (Dipl. Inf.) in Computer Science, specializing in AI, from the University of Bremen, Bjoern brings significant expertise to his role. In his spare time, Bjoern enjoys running, paragliding, mountain biking, and playing the piano.

- [LinkedIn](https://www.linkedin.com/in/bjoernmeyer/)
- [X](https://x.com/txbjoern)
- [GitHub](https://github.com/bjoerntx)

---

## Related Posts

- [TX Spell .NET 11.0 SP1 is Now Available: What's New in the Latest Version](https://www.textcontrol.com/blog/2026/04/08/tx-spell-net-11-0-sp1-is-now-available/llms.txt)
- [Create a Table of Contents in Windows Forms using C#](https://www.textcontrol.com/blog/2023/01/23/create-toc-in-windows-forms/llms.txt)
- [Official TX Text Control .NET Sample Applications Are Now Hosted on GitHub](https://www.textcontrol.com/blog/2023/01/08/official-tx-text-control-net-sample-applications-are-now-hosted-on-github/llms.txt)
- [Two Ways to Restart Numbered Lists in TX Text Control](https://www.textcontrol.com/blog/2021/11/03/two-ways-to-restart-numbered-lists/llms.txt)
- [Zoom Tricks: Disabling CTRL + MOUSE WHEEL and More](https://www.textcontrol.com/blog/2020/12/09/zoom-tricks-disabling-ctrl-mouse-wheel-and-more/llms.txt)
- [Using Custom Document Properties to Store Additional Document Information](https://www.textcontrol.com/blog/2017/02/09/using-custom-document-properties-to-store-additional-document-information/llms.txt)
- [Use SubTextParts to Protect Document Parts](https://www.textcontrol.com/blog/2015/12/29/use-subtextparts-to-protect-document-parts/llms.txt)
- [Reporting: Merging MS Word Documents with DocVariables](https://www.textcontrol.com/blog/2015/06/10/reporting-merging-ms-word-documents-with-docvariables/llms.txt)
- [Change Table Width to Fit Document Width - Automatically](https://www.textcontrol.com/blog/2005/02/03/change-table-width-to-fit-document-width-automatically/llms.txt)
