In many cases, winform also needs to be like webform. When entering some content, it will automatically display more or similar content. Baidu and Google use this method.
This makes it easier for many users to use the system you designed. In the winform design, you only need to use their autocompletemode and autocompletesource.
Method. The following is an example:
First, create a project, pull a textbox on form1, and enter it with the ComboBox control. Code Interface, write the following code in the form1_load event: Private Void Form1_load ( Object Sender, eventargs E)
{
Textbox1.autocompletecustomsource. addrange ( New String [] { " James " , " Kobe " , " T-MC " , " Jameslee " , " King " , " TOT " });
Textbox1.autocompletemode = Autocompletemode. suggestappend;
Textbox1.autocompletesource = Autocompletesource. customsource;
Combobox1.items. addrange ( New String [] { " James " , " Kobe " , " T-MC " , " Jamesli " , " King " , " TT " });
Combobox1.autocompletecustomsource. addrange ( New String [] { " James " , " Kobe " , " T-MC " , " Jameslee " , " King " , " TOT " });
Combobox1.autocompletemode = Autocompletemode. Suggest;
Combobox1.autocompletesource = Autocompletesource. customsource;
}
Note: autocompletemode has four attributes: append, none, suggest, and suggestappend:
Append is to append the first similar item to the end of your input character.
None means no prompt
Suggest displays similar items in the list
Suggestappend is to add the first similar item to the end of your input character and display all similar items in the list below.
Autocompletecustomsource is optional, but you must set the autocompletesource attribute to customsource before using autocompletecustomsource.
The autocompletemode and autocompletesource attributes must be used together.
The running result of the above Code is as follows: