In Winform, The TextBox Control Enables automatic prompt filling function, winformtextbox
Problem:In Winform development, a TextBox Control is used to enter a name. You want to automatically prompt all possible names when entering a name.
Answer:The TextBox Control in winform contains the following three attributes:
Automated completion ① AutoCompleteMode: Automatic prompt and completion method. For more information, see AutoCompleteMode enumeration;
Optional bytes ② AutoCompleteSource: the string source used for automatic prompt and completion. For specific settings, see AutoCompleteSource. When setting the value to CustomSource, you must set the ③ attribute;
Optional parameter ③ AutoCompleteCustomSource: Custom automatic prompts and complete the string source used.
Just set the above three attributes to solve the problem.
This. textBox1.AutoCompleteMode = AutoCompleteMode. suggestAppend; this. textBox1.AutoCompleteSource = AutoCompleteSource. customSource; string [] names = new string [] {"Zhang Sanfeng", "dedicated for defeat", "Feng Qingyang", "sweeping the floor"}; this. textBox1.AutoCompleteCustomSource. addRange (names );
The preceding operations are also applicable to the ComboBox control.
Thoughts:If ComboBox uses its Items attribute (that is, the drop-down list) as the string source, how do I set it?
ParameterExam:
String [] names = new string [] {"Zhang Sanfeng", "dedicated for defeat", "Feng Qingyang", "sweeping the floor"}; this. comboBox1.Items. addRange (names); this. comboBox1.AutoCompleteMode = AutoCompleteMode. suggestAppend; this. comboBox1.AutoCompleteSource = AutoCompleteSource. listItems;
Article synchronous update: http://www.motyer.cn/Files/BlogDetails/winform-textbox-autocomplete.html