winform Textbox模糊搜索实现下拉显示+提示文字
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
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<string> Data = new List<string>(); 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()[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;
} private void Form1_Load(object sender, EventArgs e)
{ } }
}

提示内容,加个变量跟两个事件
#region 实现提示文字
Boolean textboxHasText = false;//判断输入框是否有文本
/// <summary>
/// textbox获得焦点
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void textBox1_Enter(object sender, EventArgs e)
{
if (textboxHasText == false)
textBox1.Text = ""; textBox1.ForeColor = Color.Black;
} /// <summary>
/// textbox失去焦点
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void textBox1_Leave(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
textBox1.Text = "提示内容";
textBox1.ForeColor = Color.LightGray;
textboxHasText = false;
}
else
textboxHasText = true;
}
#endregion

winform Textbox模糊搜索实现下拉显示+提示文字的更多相关文章
- mui 修改下拉刷新提示文字的显示位置
第一种: .mui-bar-nav~.mui-content .mui-pull-top-pocket { top: 126px !important; } 第二种: .mui-pull-top-po ...
- winform c#绑定combobox下拉框 年度代码。
winform c#绑定combobox下拉框 年度代码. comboBox1.Items.AddRange("});//邦定数据 comboBox1.Text = DateTime.Now ...
- DataGridView单元格内容自动匹配下拉显示
页面显示数据使用的控件是ComponentFactory.Krypton.Toolkit中的KryptonDataGridView控件.在指定“商品”单元格中需要根据用户输入内容自动匹配数据库中商品信 ...
- 完美解决,浏览器下拉显示网址问题 | 完美解决,使用原生 scroll 写下拉刷新
在 web 开发过程中我们经常遇到,不想让用户下拉看到我的地址,也有时候在 div 中没有惯性滚动,就此也出了 iScroll 这种关于滚动条的框架,但是就为了一个体验去使用一个框架好像又不值得,今天 ...
- java简单的实现搜索框的下拉显示相关搜索功能
最近做了一个简单的搜索框下面下拉显示相关搜索的功能,有点模仿百度的下拉展示相关搜索 先上个展示图 : 点击进入演示地址,大家可以输入长点的搜索,点击搜索,再输入之前搜索词的前面部分,看是否能展示出来 ...
- ASP.NET TextBox 当鼠标点击后清空默认提示文字
ASP.NET TextBox 当鼠标点击后清空默认提示文字 [ 方法一] 前台代码: <div> <asp:TextBox ID="txtName" ru ...
- android 项目学习随笔十一(ListView下拉刷新提示)
1. 设置mHeaderView.setPadding TOPPADING为负值,隐藏刷新提示头布局 在onTouchEvent事件中进行头布局显示隐藏切换 import java.text.Simp ...
- QT实现输入框与下拉框提示并可模糊匹配
功能:支持下拉框选择.手动输入更改和模糊匹配 组件:QLineEdit.QComboBox.QCompleter.QStringListModel 一.组件介绍 1.1 QLineEdit QLine ...
- JQuery 简单的文字超出部分隐藏下拉显示
HTML代码: <body> <div class="txt_bos"><!--在每一个放置文字的class外面包一个div,以便设置动画样式用,同样 ...
随机推荐
- 三十 Python分布式爬虫打造搜索引擎Scrapy精讲—将selenium操作谷歌浏览器集成到scrapy中
1.爬虫文件 dispatcher.connect()信号分发器,第一个参数信号触发函数,第二个参数是触发信号,signals.spider_closed是爬虫结束信号 # -*- coding: u ...
- java开发中的重中之重-------mysql(基础篇)
介绍: mysql是目前世界上最流行的关系型数据库,在国内大的互联网公司都在使用mysql数据库,mysql经常被我们这样概述,“mysql是轻量级关系型数据库”,其实轻量级并不是说mysql是中小型 ...
- 论Sava(),SaveOrUpdate(),Merge()区别
一.Save(): 用于将一个临时对象转变为持久化对象,也就是将一个新的业务实体保存到数据库中:相当于jdbc的insert. <假如两个实体之间有关系(例如employee表和address表 ...
- Struts2异常处理配置
<package name="lee" extends="struts-default"> <!--定义全局结构映射 --> <g ...
- Spring3.0 核心jar包详解
org.springframework.aop 包含在应用中使用Spring的AOP特性时所需的类. org.springframework.asm Spring独立的ASM程序, Spring ...
- 【Error】IOError: [Errno 22] invalid mode ('wb') or filename
错误描述: IOError: [Errno 22] invalid mode ('wb') or filename: 'C:\\Users\\Viral Patel\\Documents\\GitHu ...
- MyCat入门指南
入门篇 1. 安装 1.1从https://github.com/MyCATApache/Mycat-download下载压缩包 1.2解压缩后复制到相应目录下面,比如/usr/local ...
- 016——数组(十六)usort uasort uksort
<?php /*数组 usort uasort uksort */ //usort()通过自定义函数对数组进行排序,原数组索引不保留 /*$arr = array(5, 3, 7, 6, 4, ...
- ftp的匿名用户的搭建
在搭建之前需要server端安装vsftpd用yum装就好,客户端直接装ftp就ok yum装的vsftpd直接就有共享目录,在/var/ftp/pub 目录,看下目录,给他降权,将属主,属组改为ft ...
- Unicode 和 UTF-8 有何区别? - 引自知乎
作者:于洋链接:http://www.zhihu.com/question/23374078/answer/69732605来源:知乎著作权归作者所有,转载请联系作者获得授权. 很久很久以前,有一群人 ...