文本框上的自动完成忽略重音

AutoComplete on a TextBox ignoring accentuation

我有一个自定义 TextBox 控件(它是一个自定义控件,而不是常规控件,可以在其上添加提示文本),其中我有一个 AutoComplete使用这样的 DataSet 从我的数据库中获取数据

string[] postSource = aux.Tables[0].AsEnumerable().Select<System.Data.DataRow, String>(x => x.Field<String>("nm_industria")).ToArray();
            var source = new AutoCompleteStringCollection();
            source.AddRange(postSource);

txb_regClientData.AutoCompleteCustomSource = source;
            txb_regClientData.AutoCompleteMode = AutoCompleteMode.Suggest;
            txb_regClientData.AutoCompleteSource = AutoCompleteSource.CustomSource;

它给了我这个结果 Image 如果我输入“João”,它会给我正确的结果,但如果我输入“Joao”,它不会显示,从一些关于此事的阅读中我知道 AutoComplete自动忽略重音,所以我需要自己编写代码。我的问题是,我从哪里开始呢?我理想的解决方案是覆盖自定义控件的 AutoComplete 代码中的某些内容,我阅读了 TextBox 的文档但找不到任何内容,所以如果有人能告诉我正确的方向,那么我可以阅读并学习如何做到这一点,将不胜感激。

仍有待改进,但此代码实现了解决方案,它将 listBox“附加”到 textBox,当其中多个存在时会出现问题,因为命名,但这应该是一个很好的开始 point/reference 对于寻找类似东西的人。

public class ExTextBox : TextBox
{
    private bool alreadyRun = false;
    ListBox suggestions = new ListBox();
    int maxSize = 10;
    string[] source;
    public string Hint

    public int MaxSuggestionBoxSize
    {
        get { return maxSize; }
        set { maxSize = value; this.Invalidate(); }
    }

    protected override void OnCreateControl()
    {
        if (alreadyRun == false) // This is only supposed to be run once, but in some situations depending on the design of the main form,
        {// this might need to be somewhere that gets called multiple times, this variable makes so this code is only run once even in those situations
            suggestions.Name = "suggList_" + this.Name;
            suggestions.Location = new Point(this.Location.X, (this.Location.Y + this.Size.Height));
            suggestions.Size = new Size(this.Size.Width, this.Size.Height);
            this.Parent.Controls.Add(suggestions);
            this.Parent.Controls["suggList_" + this.Name].MouseDoubleClick += suggList_MouseDoubleClick;
            this.Parent.Controls["suggList_" + this.Name].Hide();
            alreadyRun = true;
        }
        base.OnCreateControl();
    }

    private void suggList_MouseDoubleClick(object sender, System.EventArgs e)
    {
        this.Text = this.Parent.Controls["suggList_" + this.Name].Text;
    }

    protected override void OnLeave(EventArgs e)
    {
        base.OnLeave(e);
        if(source != null) // Makes sure this code is only executed when the suggestion box is being used, by checking the existance of the source
        {
            try
            {
                if (this.Parent.Controls["suggList_" + this.Name].Focused == false)
                {
                    this.Parent.Controls["suggList_" + this.Name].Hide();
                }
            }
            catch
            {

            }
        }
    }

    protected override void OnTextChanged(EventArgs e)
    {
        base.OnTextChanged(e);
        AutoCompleteSmart();
    }

    public void AutoCompleteSmart()
    {
        if (source != null)
        {
            suggestions.Items.Clear();
            if (this.Text != "")
            {
                foreach (string a in source)
                {
                    if (RemoveDiacritics(a.ToLower()).Contains(RemoveDiacritics(this.Text.ToLower())))
                    {
                        suggestions.Items.Add(a);
                    }
                }
                this.Parent.Controls.Remove(suggestions);
                if (suggestions.Items.Count < maxSize) // Optional code, defines a limit size for the suggestion box
                {
                    suggestions.Size = new Size(this.Size.Width, ((suggestions.ItemHeight * suggestions.Items.Count) + suggestions.ItemHeight));
                }
                else
                {
                    suggestions.Size = new Size(this.Size.Width, ((suggestions.ItemHeight * maxSize) + suggestions.ItemHeight));
                }

                this.Parent.Controls.Add(suggestions);
                this.Parent.Controls["suggList_" + this.Name].BringToFront();
                this.Parent.Controls["suggList_" + this.Name].Show();
            }
            else
            {
                this.Parent.Controls["suggList_" + this.Name].Hide();
            }
        }
    }

    public void AutoCompleteSmartSource(string[] _source)
    {
        source = _source;   
    }

    private static string RemoveDiacritics(string text)
    {
        var normalizedString = text.Normalize(NormalizationForm.FormD);
        var stringBuilder = new StringBuilder();

        foreach (var c in normalizedString)
        {
            var unicodeCategory = CharUnicodeInfo.GetUnicodeCategory(c);
            if (unicodeCategory != UnicodeCategory.NonSpacingMark)
            {
                stringBuilder.Append(c);
            }
        }

        return stringBuilder.ToString().Normalize(NormalizationForm.FormC);
    }
}