winform让Textbox像百度一样实现下拉显示效果

.Net技术 码拜 10年前 (2014-12-06) 1879次浏览 0个评论
下拉显示 可以提高用户体验,增加效率,如下是winform中让Textbox实现像百度一样实现下拉显示代码:
List<string> Data = new List<string>();
       string Randomstr = "我是随机字符串123热刚恢复到贴3天赋如头3广泛的我让他";
        Random rd = new Random(GetRandomSeed());
        static int GetRandomSeed()
        {
            byte[] bytes = new byte[4];
            System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider();
            rng.GetBytes(bytes);
            return BitConverter.ToInt32(bytes, 0);
        }
        public Form1()
        {
            InitializeComponent();
            for (int i = 0; i < 20000000; i++)
            {
                Data.Add(Randomstr.ToCharArray()[rd.Next(Randomstr.Length)].ToString()
                    + Randomstr.ToCharArray()[rd.Next(Randomstr.Length)].ToString()
                    + Randomstr.ToCharArray()[rd.Next(Randomstr.Length)].ToString()
                    + Randomstr.ToCharArray()[rd.Next(Randomstr.Length)].ToString()
                    + Randomstr.ToCharArray()[rd.Next(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;
        }

下面是2000W数据加载后的效果

winform让Textbox像百度一样实现下拉显示效果
效果还可以。就分享了

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明winform让Textbox像百度一样实现下拉显示效果
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!