在键入C#时查找 [英] Find as you type in C#

查看:36
本文介绍了在键入C#时查找的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试模仿输入时查找"功能,例如FireFox中的地址栏(超棒").我希望在文本框下方显示一个建议框,并且该建议框包含的字符串包含该文本框中的内容.我看了普通WinForms文本框的自动完成功能,但它似乎只搜索字符串的开头.

Im trying to emulate a 'find as you type' function like that of the address bar ("awesome bar") in FireFox. I want a suggestion box to appear below a textbox, and the suggestion box contains strings that contain what is in the textbox. I looked at the autocomplete feature of a normal WinForms textbox, but it seems to only search the beginning of the strings.

这里有没有人建造过或有实施类似经验的经验?

Has anyone here built or have experience with implementing something like this?

一些澄清-这是一个WinForms项目.它需要在字符串中搜索,而不仅仅是在开头(如果我没有记错的话,这是普通文本框的功能).并且建议应显示在弹出窗口中,例如文本框自动完成.

edit: Some clarification- It is a WinForms project. It needs to search inside a string, not just the beginning (which is what a normal textbox does if i recall correctly). And the suggestions should be displayed in a popup like a textbox autocomplete.

推荐答案

您需要为文本输入字段处理TextChanged事件,并且当文本更改时,启动一个运行新线程的线程,该线程将应用新搜索.如果在返回结果之前文本发生变化,只需终止线程即可.如果线程及时返回结果,则显示它们.

You need to handle the TextChanged event for your text entry field, and when the text changes, start a new thread running that will apply the new search. If the text changes before you get your results back, just kill the thread. If the thread returns results in time, display them.

您可以稍微提高一点(例如,在文本更改后稍等片刻,以便用户可以在不触发无用线程的情况下键入单词).

You can get slightly more advanced (e.g. wait for a short time after the text changes so that the user can type a word without you triggering off loads of useless threads) but essentially that's it.

这篇关于在键入C#时查找的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆