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. 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 method in order to create the suggestions using TX Spell .NET's Check 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. 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!