• HOME
  • PRODUCTS
  • DEMOS
  • BUY
  • BLOG
  • FORUM
  • DOCUMENTATION
  • ABOUT
  • FREE EVALUATION
Search Results for

    Show / Hide Table of Contents

    Spelling Property

    Spelling

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

    Declaration
    [Browsable(false)]
    public virtual IEditSpelling Spelling { get; }
    Property Value
    Type Description
    IEditSpelling
    Remarks

    Spelling enables TextEditor 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.

    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 MainWindow : Window
    {
        private WordList wordList = null;
    
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                string dir = AppDomain.CurrentDomain.BaseDirectory;
                if (!File.Exists(Path.GetFullPath(Path.Combine(dir, "en_us.aff"))))
                    dir = AppDomain.CurrentDomain.BaseDirectory + @"\..\..\..\";
                wordList = WordList.CreateFromFiles(Path.GetFullPath(Path.Combine(dir, "en_us.dic")), Path.GetFullPath(Path.Combine(dir, "en_us.aff")));
            }
            catch
            {
            }
    
            var textEditor = new Alternet.Editor.Wpf.TextEditor();
            textEditor.LoadFile("myfile.txt");
            textEditor.Spelling.CheckSpelling = true;
            textEditor.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 MainWindow
        Private wordList As WordList = Nothing
    
        Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
            Try
                Dim dir As String = AppDomain.CurrentDomain.BaseDirectory
                If Not File.Exists(Path.GetFullPath(Path.Combine(dir, "en_us.aff"))) Then dir = AppDomain.CurrentDomain.BaseDirectory & "\..\..\..\"
                wordList = wordList.CreateFromFiles(Path.GetFullPath(Path.Combine(dir, "en_us.dic")), Path.GetFullPath(Path.Combine(dir, "en_us.aff")))
            Catch
            End Try
    
            Dim textEditor = New Alternet.Editor.Wpf.TextEditor()
            textEditor.LoadFile("myfile.txt")
            textEditor.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
    
    In This Article
    Back to top Copyright AlterNET Software Download PDF