如何使一个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;