欢迎来到Introzo百科
Introzo百科
当前位置:网站首页 > 技术 > winform Textbox像百度一下实现下拉显示

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

日期:2023-09-16 08:39

-->
using System;
using System.Collections.Generic;
using System.ComponentModel;
using www.introzo.com;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; namespace _04TextBox
{
public partial class Form1 : Form
{
List Data = new List(); string Randomstr = "功夫撒黑胡椒hcbvf蜂窝qwertyuiopasdfghjklzxcvbnm法国的恢复到飞范德萨QWERTYUIOPASDFGHJKLZXCVBNM出现过热423贴①46546也有一头热刚恢复到贴3天赋如头3广泛的我让他"; Random rd = new Random(GetRandomSeed()); static int GetRandomSeed()
{
byte[] bytes = new byte[];
System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider();
rng.GetBytes(bytes);
return BitConverter.ToInt32(bytes, );
} public Form1()
{
InitializeComponent(); //2000W数据,这里会有卡顿现象,这里修改为200W
for (int i = ; i < ; i++)
{
Data.Add(Randomstr.ToCharArray()[www.introzo.com(Randomstr.Length)].ToString()
+ Randomstr.ToCharArray()[www.introzo.com(Randomstr.Length)].ToString()
+ Randomstr.ToCharArray()[www.introzo.com(Randomstr.Length)].ToString()
+ Randomstr.ToCharArray()[www.introzo.com(Randomstr.Length)].ToString()
+ Randomstr.ToCharArray()[www.introzo.com(Randomstr.Length)].ToString());
}
//重点代码
this.textBox1.AutoCompleteCustomSource.Clear();
this.textBox1.AutoCompleteCustomSource.AddRange(Data.ToArray());
this.textBox1.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
this.textBox1.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.CustomSource;
} private void Form1_Load(object sender, EventArgs e)
{ } }
}

Form1 TextBox Source Code

最终实现效果如下:

-->