将自动完成源(历史记录列表)的内容存储在字符串中



我只想在消息框中显示AutoCompleteSource.HistoryList。下面的代码只显示单词HistoryList。我如何才能让它真正显示HistoryLIst的URL,换句话说,我希望HistoryLIst的内容显示在MessageBox中。

var s = string.Join(Environment.NewLine, toolStripTextBox1.AutoCompleteCustomSource.OfType<string>());
MessageBox.Show(s, "History", MessageBoxButtons.OK, MessageBoxIcon.Information);
AutoCompleteSource是一个枚举,用于描述自动完成值的来源。因此,变量"s"是AutoCompleteSource.HistoryList枚举值的字符串表示形式,可能不是您要查找的值。

AutoCompleteCustomSource是自动完成字符串的集合,虽然它只显示手动输入的自动完成值,但更可能是您要查找的值。例如,如果将AutoCompleteSource枚举设置为FileSystem,它将不包含可用的FileSystem自动完全值(仅包含您在Designer或代码隐藏中手动输入的值)。

除此之外,AutoCompleteStringCollection是一个集合,为了检索所有值,您需要使用与下面显示的代码类似的代码。

var s = string.Join(Environment.NewLine, something.AutoCompleteCustomSource.OfType<string>());
MessageBox.Show(s, "History", MessageBoxButtons.OK, MessageBoxIcon.Information);

如果您试图获得URL历史记录中的实际项目列表,下面的文章可能更有用。

  • 如何获取Internet Explorer下载历史记录
  • http://hardcodedblog.blogspot.co.nz/2009/10/obtaining-browser-visited-url-history.html

最新更新