简体   繁体   English

如何让C#文本框自动完成基于包含而不是以启动为基础提出建议?

[英]How can I get C# textbox autocomplete to make suggestions based on contains rather than starts with?

I have a textbox in my C# Windows Forms application that has AutoCompleteMode set to AutoCompleteMode.Suggest, and my content source is a custom source. 我的C#Windows窗体应用程序中有一个文本框,其中AutoCompleteMode设置为AutoCompleteMode.Suggest,我的内容源是自定义源。

My content source is custom, with the following values: 我的内容源是自定义的,具有以下值:

  • Jim Smith 吉姆史密斯
  • Alice Walker 艾丽丝沃克
  • Bob Walker 鲍勃沃克
  • Jeremy Smith 杰里米史密斯

The content completion only appears to work by checking if the suggested items "start with" the value in the textbox. 通过检查建议的项目是否“以”文本框中的值“开头”,内容完成似乎起作用。

For example: 例如:

text=J

Would result in the suggestions: 会得到以下建议:

  • Jim Smith 吉姆史密斯
  • Jeremy Smith 杰里米史密斯

However, if the user types in 但是,如果用户输入

text=Walk

There are no results. 没有结果。

How can I get content completion to suggest the following? 如何完成内容以建议以下内容?

  • Alice Walker 艾丽丝沃克
  • Bob Walker 鲍勃沃克

Also, my end goal is to have a textbox where individuals can easy start typing email addresses. 此外,我的最终目标是拥有一个文本框,个人可以轻松地开始输入电子邮件地址。 The content of the autocompletion suggestions will be names + email addresses. 自动完成建议的内容将是姓名+电子邮件地址。 For example: 例如:

- Jim Smith <jsmith@mycorp.com>
- Alice Walker <alice@some.email.com>
- Bob Walker <bob.walker@mycorp.com>
- Jeremy Smith <jeremys@foo.com>

This is not possible with the built-in TextBox. 内置TextBox无法实现这一点。

Reading the reference source reveals that the AutoComplete feature calls into the native function SHAutoComplete to do it's job. 读取参考源会发现AutoComplete功能会调用本机函数SHAutoComplete来完成它的工作。 That one does only prefix matching. 那只做前缀匹配。

You would have to subclass TextBox and provide your own suggestion feature (or purchase one / find an open source one), to do this. 你必须继承TextBox的子类并提供你自己的建议功能(或购买一个/找到一个开源的功能)来做到这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM