0

我正在寻找一个用于文本控件中自动完成支持的库,它可以记住用户以前的所有条目并为其提供自动完成支持。

例如,对于“最近的文件”,我使用http://www.genghisgroup.com/,效果很好。你知道类似的东西吗?

更新:这是一个 .NET Winforms 应用程序,我使用的是普通的文本控件。

4

2 回答 2

1

内置在 .NET TextBox 中的是 AutoComplete 功能。首先设置 AutoCompleteMode 属性(Suggest、Append 等),然后选择 AutoCompleteSource。您的选择是:

FileSystem HistoryList RecentUsedList AllUrl AllSystemSources FileSystemDirectories CustomSource 无 ListItems

在您的情况下,您将使用 CustomSource,然后填充作为 TextBox 上的属性的 AutoCompleteCustomSource 集合。我建议有一个简单的 SqlCe 数据库,您可以在其中存储用户过去输入的值,然后在加载应用程序时检索这些值,并填充 AutoCompleteCustomSource。

快速代码示例:

private void button1_Click(object sender, EventArgs e)
{
    this.textBox1.AutoCompleteMode = AutoCompleteMode.Suggest;
    this.textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;

    string[] items = GetListForCustomSource();
    this.textBox1.AutoCompleteCustomSource.AddRange(items);

}

private string[] GetListForCustomSource()
{
    var result = new List<string>();

    foreach(var value in Enum.GetNames(typeof(DayOfWeek)))
    {
        result.Add(value);
    }

    return result.ToArray();
}

我只是以 DayOfWeek 为例,但您可以在该方法中查询数据库,并返回结果。

于 2009-02-22T15:27:20.810 回答
0

下载源代码并查看最近的文件。毫无疑问,它正在存储某种形式的持久存储(数据库、文件等)并使用该信息来填写列表。您只是欺骗了该功能,并将其用于专注于单词而不是文件的 TextBox。

我没有看过 Genghis 的源代码,但我确信通过你使用的具有类似功能的控件运行并欺骗它是很容易的。当您这样做时,请联系 Genghis 集团并将其作为提交内容提供。这就是我们支持开源的方式。

于 2009-02-22T15:10:20.820 回答