我有这个由 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;
}
}
这本词典:
而且,这个结果:
我尝试了 *.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/