Table of Contents

Property Spelling

Namespace
Alternet.Editor
Assembly
Alternet.Editor.v9.dll

Spelling

Represents object that implements IEditSpelling interface containing properties and methods to check control's content spelling and highlight misspelled words.

[TypeConverter(typeof(ExpandableObjectConverter))]
public virtual IEditSpelling Spelling { get; set; }

Property Value

IEditSpelling

Examples

Here is how to use a Spelling in the C# code:

using System.IO;
using System.Windows.Forms;
using Alternet.Editor.TextSource;
using Alternet.Syntax.Lexer;
using WeCantSpell.Hunspell;

public partial class Form1 : Form
{
    private WordList wordList = null;

    private void Form1_Load(object sender, EventArgs e)
    {
        try
        {
            string dir = Application.StartupPath;
            if (!File.Exists(Path.GetFullPath(Path.Combine(dir, "en_us.aff"))))
                dir = Application.StartupPath + @"\..\..\..\";
            wordList = WordList.CreateFromFiles(Path.GetFullPath(Path.Combine(dir, "en_us.dic")), Path.GetFullPath(Path.Combine(dir, "en_us.aff")));
        }
        catch
        {
        }

        var syntaxEdit1 = new Alternet.Editor.SyntaxEdit(this.components);
        syntaxEdit1.LoadFile("myfile.txt");
        syntaxEdit1.Spelling.CheckSpelling = true;
        syntaxEdit1.Spelling.WordSpell += new WordSpellEvent(WordSpell);
    }

    private void WordSpell(object sender, WordSpellEventArgs e)
    {
        ITextSource source = (ITextSource)sender;
        bool correct = (wordList != null) ? wordList.Check(e.Text) : true;
        if (source.Lexer != null)
        {
            LexToken tok = (LexToken)(e.ColorStyle.Data - 1);
            if ((tok == LexToken.String) || (tok == LexToken.Comment) || (tok == LexToken.XmlComment))
                e.Correct = (e.Text.Length <= 1) || correct;
        }
        else
            e.Correct = (e.Text.Length <= 1) || correct;
    }
}

Here is how to use a Spelling in the Visual Basic code:

Imports System.IO
Imports System.Windows.Forms
Imports Alternet.Editor.TextSource
Imports Alternet.Syntax.Lexer
Imports WeCantSpell.Hunspell

Partial Public Class Form1
    Inherits Form

    Private wordList As WordList = Nothing

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
        Try
            Dim dir As String = Application.StartupPath
            If Not File.Exists(Path.GetFullPath(Path.Combine(dir, "en_us.aff"))) Then dir = Application.StartupPath & "\..\..\..\"
            wordList = wordList.CreateFromFiles(Path.GetFullPath(Path.Combine(dir, "en_us.dic")), Path.GetFullPath(Path.Combine(dir, "en_us.aff")))
        Catch
        End Try

        Dim syntaxEdit1 = New Alternet.Editor.SyntaxEdit(Me.components)
        syntaxEdit1.LoadFile("myfile.txt")
        syntaxEdit1.Spelling.CheckSpelling = True
        AddHandler syntaxEdit1.Spelling.WordSpell, New WordSpellEvent(AddressOf WordSpell)
    End Sub

    Private Sub WordSpell(ByVal sender As Object, ByVal e As WordSpellEventArgs)
        Dim source As ITextSource = CType(sender, ITextSource)
        Dim correct As Boolean = If((wordList IsNot Nothing), wordList.Check(e.Text), True)

        If source.Lexer IsNot Nothing Then
            Dim tok As LexToken = CType((e.ColorStyle.Data - 1), LexToken)
            If (tok = LexToken.String) OrElse (tok = LexToken.Comment) OrElse (tok = LexToken.XmlComment) Then e.Correct = (e.Text.Length <= 1) OrElse correct
        Else
            e.Correct = (e.Text.Length <= 1) OrElse correct
        End If
    End Sub
End Class

Remarks

Spelling enables SyntaxEdit control to provide the spelling of the text as the user types.

To enable the spelling checker, set CheckSpelling property to true. When this spelling checker is enabled, misspelled words are underlined using a wavy line by color specified in the SpellColor property.

To provide real-world spelling, you will need to implement check spelling logic using third-party dictionaries.