winform Textbox像百度一下实现下拉显示

 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Threading.Tasks;
 9 using System.Windows.Forms;
10 
11 namespace _04TextBox
12 {
13     public partial class Form1 : Form
14     {
15         List<string> Data = new List<string>();
16 
17         string Randomstr = "功夫撒黑胡椒hcbvf蜂窝qwertyuiopasdfghjklzxcvbnm法国的恢复到飞范德萨QWERTYUIOPASDFGHJKLZXCVBNM出现过热423贴①46546也有一头热刚恢复到贴3天赋如头3广泛的我让他";
18 
19 
20         Random rd = new Random(GetRandomSeed());
21 
22         static int GetRandomSeed()
23         {
24             byte[] bytes = new byte[4];
25             System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider();
26             rng.GetBytes(bytes);
27             return BitConverter.ToInt32(bytes, 0);
28         }
29 
30         public Form1()
31         {
32             InitializeComponent();
33 
34             //2000W数据,这里会有卡顿现象,这里修改为200W
35             for (int i = 0; i < 2000000; i++)
36             {
37                 Data.Add(Randomstr.ToCharArray()[rd.Next(Randomstr.Length)].ToString()
38                     + Randomstr.ToCharArray()[rd.Next(Randomstr.Length)].ToString()
39                     + Randomstr.ToCharArray()[rd.Next(Randomstr.Length)].ToString()
40                     + Randomstr.ToCharArray()[rd.Next(Randomstr.Length)].ToString()
41                     + Randomstr.ToCharArray()[rd.Next(Randomstr.Length)].ToString());
42             }
43             //重点代码
44             this.textBox1.AutoCompleteCustomSource.Clear();
45             this.textBox1.AutoCompleteCustomSource.AddRange(Data.ToArray());
46             this.textBox1.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
47             this.textBox1.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.CustomSource;
48         }
49 
50         private void Form1_Load(object sender, EventArgs e)
51         {
52 
53         }
54 
55     }
56 }
Form1 TextBox Source Code

最终实现效果如下:

winform Textbox像百度一下实现下拉显示_第1张图片

winform Textbox像百度一下实现下拉显示_第2张图片

转载于:https://www.cnblogs.com/DrHao/p/4953194.html

你可能感兴趣的:(winform Textbox像百度一下实现下拉显示)