如何使一个WinForms桌面应用程序自动完成的文本框 [英] How to make an auto-complete textbox in a winforms desktop application

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

问题描述

我有个词语的列表。该列表包含约100-200文本字符串。

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

我想打一个自动完成的文本框。举个例子,用户preSS'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的链接断开,这里的一些code,做的伎俩:

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天全站免登陆