如何在 winforms 桌面应用程序中制作自动完成文本框 [英] How to make an auto-complete textbox in a winforms desktop application

查看:15
本文介绍了如何在 winforms 桌面应用程序中制作自动完成文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个单词列表.该列表包含大约 100-200 个文本字符串(实际上是地铁站的名称).

I have a list of words. The list contains about 100-200 text strings (it's names of metro stations actually).

我想制作一个自动完成的文本框.例如,用户按N"字母,然后出现一个(结尾)适当的选项(只有一个选项).必须选择结尾.

I want to make an auto-complete textbox. For an example, user press 'N' letter, then an (ending of) appropriate option appear (only one option). The ending must be selected.

怎么做?

PS1:我猜,有一个带有类似这样的属性的文本框控件:

PS1: I guess, there is a textbox control with a Property something like this:

List<string> AppropriateOptions{/* ... */}

PS2:对不起我的英语.如果你不明白 -> 问我,我会尽力解释!

PS2: sorry for my english. If you didn't understand -> ask me and I will try to explain!

推荐答案

以防万一@leniel 的链接失效,这里有一些代码可以解决问题:

Just in case @leniel's link goes down, here's some code that does the trick:

AutoCompleteStringCollection allowedTypes = new AutoCompleteStringCollection();
allowedTypes.AddRange(yourArrayOfSuggestions);
txtType.AutoCompleteCustomSource = allowedTypes;
txtType.AutoCompleteMode = AutoCompleteMode.Suggest;
txtType.AutoCompleteSource = AutoCompleteSource.CustomSource;

这篇关于如何在 winforms 桌面应用程序中制作自动完成文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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