winform 自动填充功能,一般使用AutoCompleteSource,
绑定string[],和文件,
1: private void FormMain_Load(object sender, EventArgs e)
2: {
3: //窗体加载事件处理方法
4: this.InitTextBox();
5: }
6:
7: private void InitTextBox()
8: {
9: //初始化文本框(TextBox控件)
10: this.txtAutoComplete.AutoCompleteSource = AutoCompleteSource.CustomSource;
11: this.txtAutoComplete.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
12: this.txtAutoComplete.AutoCompleteCustomSource = this.InitCompleteCollection();
13: }
14:
15: private AutoCompleteStringCollection InitCompleteCollection()
16: {
17: //这里是将文件的信息加载到CompleteCollection中,只要你愿意,可以将任何文本数据放入其中
18: AutoCompleteStringCollection collection = new AutoCompleteStringCollection();
19:
20: StreamReader sr = new StreamReader("collection.txt");
21: while (!sr.EndOfStream)
22: {
23: string strTemp = sr.ReadLine();
24: collection.Add(strTemp);
25: }
26: sr.Close();
27:
28: return collection;
29: }