c# - 为什么 SpellCheck 总是将附加词典(utf-8、带 BOM 的 utf-8、UTF-16)中的单词标记为错误?

标签 c# .net winforms spell-checking

我有这个由 Hans Passant 制作的控件,我从这里抓取了它 ( Trying to use the C# SpellCheck class ) 并进行了修改以加载其他字典:

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;
    }
}

这本词典:

enter image description here

而且,这个结果:

enter image description here

我尝试了 *.lex 的不同编码,但单词仍然标记为错误。

lex 具有所需的 LID:

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

怎么了?

最佳答案

我可以通过执行以下操作来学习法语:

  • 使用 1252 编码保存文件
  • 设置文本框的语言
  • 在 lex 文件中将 #LID 设置为 1036

使用包含以下内容的文件进行测试:ééé

例如

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));

不幸的是,这不适用于俄语。默认情况下似乎仅支持 4 种语言。请参阅Does SpellCheck .Net class support russian language?了解更多信息。

关于c# - 为什么 SpellCheck 总是将附加词典(utf-8、带 BOM 的 utf-8、UTF-16)中的单词标记为错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25658323/

相关文章:

C# 从 DLL 加载资源 (ResourceManager)

c# - 为 C# 做 SCP 的库

c# - 有用的迷你模式(不是设计模式)

c# - 异常处理中的异常处理

c# - 从解决方案中的另一个文件访问 Windows 形式的数组

c# - WinForms.ReportViewer - 呈现的页面数

c# - 如何在 Raspberry PI 上使用 UWP 应用程序设置系统时间

c# - Nuget 返回意外状态代码 '404 Not Found' - 本地驱动器上的包

c# - SharpSVN - 无论如何都会收到待处理更新的通知吗?

c# - 如何从子表单打开表单并在主表单面板中显示