Skip to main content
A newer version of this page is available. .

ISpellChecker.Check(Object, ISpellCheckTextController, Position, Position) Method

Checks the spelling of the text available through the controller interface in the specified range and returns on the first error that occurrs.

Namespace: DevExpress.XtraSpellChecker

Assembly: DevExpress.Data.v18.2.dll

Declaration

ISpellingErrorInfo Check(
    object control,
    ISpellCheckTextController controller,
    Position from,
    Position to
)

Parameters

Name Type Description
control Object

An object that is a control to be checked for spelling mistakes.

controller DevExpress.XtraSpellChecker.Parser.ISpellCheckTextController

An object implementing the DevExpress.XtraSpellChecker.Parser.ISpellCheckTextController interface providing text to check.

from DevExpress.XtraSpellChecker.Parser.Position

A DevExpress.XtraSpellChecker.Parser.Position object containing information on the position where the check statrs.

to DevExpress.XtraSpellChecker.Parser.Position

A DevExpress.XtraSpellChecker.Parser.Position object containing information on the position where the check finishes.

Returns

Type Description
ISpellingErrorInfo

An object with the ISpellingErrorInfo interface providing information on the error type and position.

Remarks

using System.Reflection;
using System.Windows.Forms;
using DevExpress.XtraSpellChecker;
using DevExpress.XtraSpellChecker.Parser;

namespace SpellCheckerSample {
    public partial class Form1 : Form {
        DevExpress.XtraSpellChecker.Native.RichTextBoxTextController controller;

        public Form1() {
            InitializeComponent();
            richTextBox1.LoadFile(Assembly.GetExecutingAssembly().GetManifestResourceStream("SpellCheckerSample.Data.SpellChecker.rtf"), RichTextBoxStreamType.RichText);
            controller = new DevExpress.XtraSpellChecker.Native.RichTextBoxTextController(richTextBox1);
            FindErrors(new IntPosition(0), new IntPosition(richTextBox1.TextLength));
            richTextBox1.TextChanged += OnTextChanged;
        }

        void FindErrors(Position startPos, Position endPos) {
            Position start = startPos.Clone();
            Position end = endPos.Clone();
            ISpellingErrorInfo errorInfo = null;
            do {
                errorInfo = ((ISpellChecker)spellChecker1).Check(richTextBox1, controller, start, end);
                if (errorInfo != null) {
                    start = errorInfo.WordEndPosition;
                    HighlightText(errorInfo.WordStartPosition, errorInfo.WordEndPosition, Color.Red);
                }
                else
                    HighlightText(start, end, Color.Black);
            } while (errorInfo != null);
        }
        void HighlightText(Position start, Position end, Color color) {
            int cachedSelectionStart = richTextBox1.SelectionStart;
            controller.Select(start, end);
            richTextBox1.SelectionColor = color;

            richTextBox1.SelectionStart = cachedSelectionStart;
            richTextBox1.SelectionLength = 0;
        }
        void OnTextChanged(object sender, System.EventArgs e) {
            Position currentPosition = new IntPosition(richTextBox1.SelectionStart);
            Position start = GetPrevWordPosition(currentPosition);
            Position end = controller.GetNextPosition(currentPosition);
            FindErrors(start, end);
        }
        Position GetPrevWordPosition(Position pos) {
            return controller.GetPrevPosition(controller.GetPrevPosition(pos));
        }
    }
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the Check(Object, ISpellCheckTextController, Position, Position) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also