Title Back Colour Keyoti Title Line Title Curve
Blue Box Top

How to highlight words in a dictionary

RapidSpell Desktop .NET


This tutorial will demonstrate how to highlight words within a text box that match those from a separate source (hard coded here for simplicity). In our example, words such as 'gosh', 'darn', 'doodle' will have a double underline to highlight positive matches.

Positive word matches

By using two instances of our RapidSpellAsYouType control, we can use one instance for our normal spell checking function and the other for highlighting positive word matches.

In the code below we are subclassing RapidSpellChecker to create 'FlandersParser', which is then assigned to rapidSpellAsYouType_Highlights.RapidSpellChecker.

By doing that we override the default behavior, which is to flag words that are NOT in a dictionary, and instead flag words that ARE in our dictionary.

Both instances of RapidSpellAsYouType will have their underline style & color properties set differently to make it clear whether the highlight is for spell checking or for the new positive word match.

The FindSuggestions method can be modified to provide custom suggestions as needed.

The full project demonstrating positive word matches can be downloaded here.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Highlighter
    /// <summary>
    /// A basic text parser, looks for Flanderisms and censors.
    /// </summary>
    public class FlandersParser : Keyoti.RapidSpell.RapidSpellChecker
        Hashtable dictionary = new Hashtable();
        string suggestion = null;

        Keyoti.RapidSpell.FrameWorkSpecific.AdvancedTextBoundary wordIterator = new Keyoti.RapidSpell.FrameWorkSpecific.AdvancedTextBoundary();

        public FlandersParser()
            //load dictionary of flanderisms, a real offensive word parser would of course
            //have a list of offensive words here.
            IgnoreIncorrectSentenceCapitalization = true;
            IgnoreInEnglishLowerCaseI = true;
            WarnDuplicates = false;
            TextBoundary = wordIterator;


        protected override bool LookUpMainDictionary(string query)
            return !dictionary.ContainsKey(query); //opposite to how spell check works - highlight if is in dictionary, hence the not (!)

        public override ArrayList FindSuggestions()
            ArrayList s = new ArrayList();
            if (suggestion != null) s.Add(suggestion);
            return s;

About | Contact | Site Map | Privacy Policy

Copyright © 2002- Keyoti Inc.