2

I have this control made by Hans Passant, that I grabbed from here (Trying to use the C# SpellCheck class) and modified to load additional dictionary:

using System;
using System.Windows;
using System.ComponentModel;
using System.Windows.Controls;
using System.Windows.Forms.Integration;

namespace SoAL_TextExtractor
{
    class SpellBox : ElementHost
    {
        public SpellBox()
        {
            box = new TextBox();
            base.Child = box;
            box.TextChanged += (s, e) => OnTextChanged(EventArgs.Empty);
            Uri lex_file = new Uri(System.Windows.Forms.Application.StartupPath + "\\Russian.lex");
            box.SpellCheck.CustomDictionaries.Add(lex_file);
            box.SpellCheck.IsEnabled = true;
            box.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
            this.Size = new System.Drawing.Size(100, 20);
        }
        public override string Text
        {
            get { return box.Text; }
            set { box.Text = value; }
        }
        [DefaultValue(false)]
        public bool Multiline
        {
            get { return box.AcceptsReturn; }
            set { box.AcceptsReturn = value; }
        }
        [DefaultValue(false)]
        public bool WordWrap
        {
            get { return box.TextWrapping != TextWrapping.NoWrap; }
            set { box.TextWrapping = value ? TextWrapping.Wrap : TextWrapping.NoWrap; }
        }
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public new System.Windows.UIElement Child
        {
            get { return base.Child; }
            set { /* Do nothing to solve a problem with the serializer !! */ }
        }
        private TextBox box;
    }
}

This dictionary:

enter image description here

And, this result:

enter image description here

I tried different encodings for *.lex but words still marked as bad.

lex has the LID as needed:

#LID 1049
абажур
абажура
...

What's up?

Community
  • 1
  • 1
Kosmo零
  • 4,001
  • 9
  • 45
  • 88
  • You can't just copy somebody else's code and repost it as though it is your own. Attribution is required, look at the bottom of the page for details. – Hans Passant Sep 04 '14 at 09:52
  • @HansPassant - excuse me? Where did I said it's my code? All I said is "I have this control". I know this is grabbed from another answer, but I never told this is mine. I using it, I have problems with it and I showing here what I have. – Kosmo零 Sep 04 '14 at 13:42
  • The license doesn't say anything about that. It is an exceedingly simple rule, when you repost somebody else's work then you **must** attribute. Always. Please take care of it. – Hans Passant Sep 04 '14 at 14:11
  • Oh huh, so you are the author. I added credits to my questions. Also, question solved by removing LID from lex. – Kosmo零 Sep 04 '14 at 15:06
  • @Kosmos I tested removing the LID and that didn't solve the problem. It resulted in none of the words being underlined as misspelled. – Loathing Sep 05 '14 at 18:38
  • 1
    @Loathing - Well, this is the differences that we probably have: 1 - **I do not set: `box.Language = /*to anything*/;`.** 2 - **My lex is saved in UTF-16, while you said it's in 1252 code page**. On msdn said that: **If the locale is not specified, the dictionary applies to all languages.**... So, i don't know how, but the SpellCheck is work for me as expected. – Kosmo零 Sep 06 '14 at 06:27
  • I confirm UTF-16 with no language setting and no LID works. Surprising how giving more information causes it to not work as one would expect. Thanks. – Loathing Sep 06 '14 at 06:42

1 Answers1

2

I was able to get French working by doing the following:

  • saving file using 1252 encoding
  • setting the language on the text box
  • setting the #LID to 1036 in the lex file

Testing using a file containing: ééé

e.g.

box.Language = System.Windows.Markup.XmlLanguage.GetLanguage("fr");
String text = System.IO.File.ReadAllText(lex_file.AbsolutePath, Encoding.UTF8);
System.IO.File.WriteAllText(lex_file.AbsolutePath, text, Encoding.GetEncoding(1252));

Unfortunately, this doesn't work for Russian. It appears only 4 languages are supported by default. See Does SpellCheck .Net class support russian language? for more information.

Community
  • 1
  • 1
Loathing
  • 5,109
  • 3
  • 24
  • 35