zoukankan      html  css  js  c++  java
  • 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

    最终实现效果如下:

  • 相关阅读:
    sql命令附加数据库
    数据解析0102
    xml file parser
    c#字定义异常处理类
    simple workflow implement
    High Performance Multithreaded Work Item / Event Scheduling Engine
    字符定位
    C#实现的不重复随机数序列生成算法
    Thread并发数控制
    通过Assembly来创建Type Instance
  • 原文地址:https://www.cnblogs.com/DrHao/p/4953194.html
Copyright © 2011-2022 走看看