# TX Spell .NET: Creating Custom Context Menus

> Custom spell checking context menus in TX Spell .NET use the SpellCheckContextMenuStrip property and MisspelledWords.GetItem method to detect the word at the mouse position. The code dynamically populates menu items with suggestions and replaces misspelled words on click.

- **Author:** Bjoern Meyer
- **Published:** 2012-01-04
- **Modified:** 2026-07-17
- **Description:** Custom spell checking context menus in TX Spell .NET use the SpellCheckContextMenuStrip property and MisspelledWords.GetItem method to detect the word at the mouse position. The code dynamically populates menu items with suggestions and replaces misspelled words on click.
- **2 min read** (380 words)
- **Tags:**
  - Sample
  - Spell Checking
- **Web URL:** https://www.textcontrol.com/blog/2012/01/04/tx-spell-net-creating-custom-context-menus/
- **LLMs URL:** https://www.textcontrol.com/blog/2012/01/04/tx-spell-net-creating-custom-context-menus/llms.txt
- **LLMs-Full URL:** https://www.textcontrol.com/blog/2012/01/04/tx-spell-net-creating-custom-context-menus/llms-full.txt

---

Using context menus in TX Spell .NET is very simple: When connected to TX Text Control, the built-in context menu works out-of-the-box without implementing a single line of code. TX Text Control automatically replaces the default context menu with the built-in spell checking context menu.

But sometimes, you need to build your own menu or you want to combine two context menus. For this purpose, TX Text Control provides the property [SpellCheckContextMenuStrip](https://docs.textcontrol.com/textcontrol/windows-forms/ref.txtextcontrol.textcontrol.spellcheckcontextmenustrip.property.htm). This property specifies the context menu which is used when the end-user right-clicks a misspelled word.

In the *Opening* event of the context menu strip, we simply need to get the misspelled word at the current mouse position using the [MisspelledWords.GetItem](https://docs.textcontrol.com/textcontrol/windows-forms/ref.txtextcontrol.misspelledwordcollection.getitem.method.htm) method in order to create the suggestions using TX Spell .NET's [Check](https://docs.textcontrol.com/spell/windows-forms/ref.txtextcontrol.proofing.txspell.check.method.htm) method. Each suggestion is used to create a new *ToolStripMenuItem* dynamically that is added to the custom context menu.

```
private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
{
    // clear all items from the context menu
    contextMenuStrip1.Items.Clear();

    // get the conversion rate twips vs. pixel
    int dpi = (int)(1440 / textControl1.CreateGraphics().DpiX);

    // get the location of the mouse
    Point location = new Point(
        (int)(textControl1.PointToClient(MousePosition).X * dpi),
        (int)(textControl1.PointToClient(MousePosition).Y * dpi));

    // get the misspelled word at the mouse locaion
    word = textControl1.MisspelledWords.GetItem(location);

    if (word == null)
        return;

    txSpellChecker1.CreateSuggestions(word.Text);

    // fill up the context menu
    foreach (Suggestion suggestion in txSpellChecker1.Suggestions)
    {
        ToolStripMenuItem item = new ToolStripMenuItem(suggestion.Text);
        // attach the click handler
        item.Click += new EventHandler(item_Click);

        contextMenuStrip1.Items.Add(item);
    }

    if (contextMenuStrip1.Items.Count == 0)
        contextMenuStrip1.Items.Add("No suggestions found.");
}
```

Finally, on clicking a menu item, the misspelled word is replaced with the selected suggestion text:

```
void item_Click(object sender, EventArgs e)
{
    // replace the misspelled word with the clicked suggestion
    textControl1.MisspelledWords.Remove(word, ((ToolStripMenuItem)sender).Text);
}
```

Download the Visual Studio 2008 project [here](https://s1-www.textcontrol.com/assets/dist/blog/2012/01/04/a/assets/txspell_usercontextmenu.zip). At least a TX Text Control .NET for Windows Forms 17.0 trial version and a TX Spell .NET for Windows Forms trial version is required. 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

- [Interactive Spelling Suggestions Using TX Spell .NET](https://www.textcontrol.com/blog/2014/07/30/interactive-spelling-suggestions-using-tx-spell-net/llms.txt)
- [Spell Checking, MailMerge and UserDictionaries](https://www.textcontrol.com/blog/2012/11/19/spell-checking-mailmerge-and-userdictionaries/llms.txt)
- [Porting RapidSpell to TX Spell .NET](https://www.textcontrol.com/blog/2011/12/22/porting-rapidspell-to-tx-spell-net/llms.txt)
- [Using the WSpell ActiveX Spelling Checker with TX Text Control](https://www.textcontrol.com/blog/2003/06/24/using-the-wspell-activex-spelling-checker-with-tx-text-control/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)
- [Detect Toggle Button Changes Using a MutationObserver](https://www.textcontrol.com/blog/2021/11/11/detect-toggle-button-changes-using-a-mutationobserver/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)
- [Service Pack 1 for TX Spell .NET 7.0 Released](https://www.textcontrol.com/blog/2019/05/28/service-pack-1-for-spell-7-released/llms.txt)
- [Proofing Tools Available As ReportingCloud Web API Endpoints](https://www.textcontrol.com/blog/2017/08/23/proofing-tools-available-as-reportingcloud-web-api-endpoints/llms.txt)
- [AutoCorrect Using TX Text Control and TX Spell .NET](https://www.textcontrol.com/blog/2017/08/17/autocorrect-using-tx-text-control-and-tx-spell-net/llms.txt)
- [Creating Conference Badges with Text Control Reporting](https://www.textcontrol.com/blog/2017/02/14/creating-conference-badges-with-text-control-reporting/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)
- [Using TX Spell .NET with ServerTextControl](https://www.textcontrol.com/blog/2016/04/26/using-tx-spell-net-with-servertextcontrol/llms.txt)
- [Use SubTextParts to Protect Document Parts](https://www.textcontrol.com/blog/2015/12/29/use-subtextparts-to-protect-document-parts/llms.txt)
- [HTML5: Enable Spell Checking Using Javascript](https://www.textcontrol.com/blog/2015/10/08/html5-enable-spell-checking-using-javascript/llms.txt)
- [Reporting: Styling the DocumentViewer for ASP.NET](https://www.textcontrol.com/blog/2015/06/14/reporting-styling-the-documentviewer-for-aspnet/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)
- [TextControl.Web: Determine when a Document Has Been Completely Loaded](https://www.textcontrol.com/blog/2015/06/09/textcontrolweb-determine-when-a-document-has-been-completely-loaded/llms.txt)
- [TextControl.Web: Adding Custom Ribbon Tabs](https://www.textcontrol.com/blog/2015/05/29/textcontrolweb-adding-custom-ribbon-tabs/llms.txt)
- [Building a Touch-enabled Button Bar with Javascript](https://www.textcontrol.com/blog/2015/05/27/building-a-touch-enabled-button-bar-with-javascript/llms.txt)
- [TextControl.Web: Inserting Merge Fields Using Javascript](https://www.textcontrol.com/blog/2015/05/16/textcontrolweb-inserting-merge-fields-using-javascript/llms.txt)
- [MailMerge: Merge Hyperlinks into Merge Fields](https://www.textcontrol.com/blog/2015/05/15/mailmerge-merge-hyperlinks-into-merge-fields/llms.txt)
- [Web.TextControl and Spell Checking](https://www.textcontrol.com/blog/2015/02/09/webtextcontrol-and-spell-checking/llms.txt)
