WinForm中自定义搜索框(水印、清空按钮、加载中图标)
public partial class CustomSearchBar : TextBox
{
private readonly Label lblwaterText = new Label(); private readonly PictureBox clearButton = new PictureBox(); private readonly int cancelImageSize = ; private int loadingCharsCount = ; public CustomSearchBar()
{
InitializeComponent(); lblwaterText.BorderStyle = BorderStyle.None;
lblwaterText.Enabled = false;
lblwaterText.BackColor = Color.White;
lblwaterText.AutoSize = false;
lblwaterText.Top = ;
lblwaterText.Left = ;
lblwaterText.FlatStyle = FlatStyle.System;
Controls.Add(lblwaterText); clearButton.Size = new Size(cancelImageSize, cancelImageSize);
//clearButton.AutoSize = false;
clearButton.SizeMode = PictureBoxSizeMode.StretchImage;
//clearButton.Image = ResourceHandler.LoadImage("Loading");
clearButton.Top = ;
clearButton.Left = this.Width - cancelImageSize - ;
clearButton.Click += new EventHandler(clearButton_Click);
Controls.Add(clearButton);
} public void AdjustClearButtonPosition(int width)
{
this.clearButton.Left = width - cancelImageSize - ;
} public string WaterText
{
get { return lblwaterText.Text; }
set { lblwaterText.Text = value; }
} public override string Text
{
set
{
lblwaterText.Visible = value == string.Empty;
base.Text = value;
}
get
{
return base.Text;
}
} protected override void OnSizeChanged(EventArgs e)
{
if (Multiline && (ScrollBars == ScrollBars.Vertical || ScrollBars == ScrollBars.Both))
lblwaterText.Width = Width - ;
else
lblwaterText.Width = Width;
lblwaterText.Height = Height - ;
base.OnSizeChanged(e);
} protected override void OnTextChanged(EventArgs e)
{
lblwaterText.Visible = base.Text == string.Empty;
base.OnTextChanged(e);
} protected override void OnMouseDown(MouseEventArgs e)
{
lblwaterText.Visible = false;
base.OnMouseDown(e);
} protected override void OnMouseLeave(EventArgs e)
{
lblwaterText.Visible = base.Text == string.Empty;
base.OnMouseLeave(e);
} /// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void clearButton_Click(object sender, EventArgs e)
{
this.Text = string.Empty;
ClearSearchingTextHandler();
} public void StartLoadSmartTip()
{
this.clearButton.Image = ResourceHandler.LoadImage("Loading");
loadingCharsCount++;
} public void EndLoadSmartTip()
{
loadingCharsCount--;
if (loadingCharsCount <= )
{
this.clearButton.Image = ResourceHandler.LoadImage("CloseButtonInactive");
}
} public delegate void ClearSearchingText();
public event ClearSearchingText ClearSearchingTextHandler;
}
WinForm中自定义搜索框(水印、清空按钮、加载中图标)的更多相关文章
- 使用Bootstrap3和Ladda UI实现的多种按钮“加载中”效果体验
在线演示 在线演示 大家在开发基于web的网站或者web应用中,常常在AJAX调用的过程中需要提示用户并且展示相关的“加载中”效果,类似的UI设计也非常多,比如,当点击一个按钮后,在它的旁边显示一个 ...
- WPF实用指南一:在WPF窗体的边框中添加搜索框和按钮
原文:WPF实用指南一:在WPF窗体的边框中添加搜索框和按钮 在边框中加入一些元素,在应用程序的界面设计中,已经开始流行起来.特别是在浏览器(Crome,IE,Firefox,Opera)中都有应用. ...
- bootStrap-table服务器端后台分页的使用,以及自定义搜索框的实现,前端代码到数据查询超详细讲解
关于分页,之前一直纯手写js代码来实现,最近又需要用到分页,找了好多最终确定bootstrap-table,正好前端页面用的是bootstrap. 首先下载BootStrap-table的js和CSS ...
- iOS开发UI篇 -- UISearchBar 属性、方法详解及应用(自定义搜索框样式)
很多APP都会涉及到搜索框,苹果也为我们提供了默认的搜索框UISearchBar.但实际项目中我们通常需要更改系统默认搜索框的样式.为了实现这一目标,我们需要先搞懂 UISearchBar 的属性及方 ...
- extjs在窗体中添加搜索框
在extjs中添加搜索框,搜索框代码如下: this.searchField = new Ext.ux.form.SearchField({ store : this.store ...
- Qt之自定义搜索框
简述 关于搜索框,大家都经常接触.例如:浏览器搜索.Windows资源管理器搜索等. 当然,这些对于Qt实现来说毫无压力,只要思路清晰,分分钟搞定. 方案一:调用QLineEdit现有接口 void ...
- 【Qt】Qt之自定义搜索框【转】
简述 关于搜索框,大家都经常接触.例如:浏览器搜索.Windows资源管理器搜索等. 当然,这些对于Qt实现来说毫无压力,只要思路清晰,分分钟搞定. 简述 效果 细节分析 Coding 源码下载 效果 ...
- Qt之自定义搜索框——QLineEdit里增加一个Layout,还不影响正常输入文字(好像是一种比较通吃的方法)
简述 关于搜索框,大家都经常接触.例如:浏览器搜索.Windows资源管理器搜索等. 当然,这些对于Qt实现来说毫无压力,只要思路清晰,分分钟搞定. 方案一:调用QLineEdit现有接口 void ...
- Android自定义View——自定义搜索框(SearchView)
Android自定义View——自定义搜索框(SearchView) http://www.apkbus.com/android-142064-1-1.html
随机推荐
- PHP5.3.8连接Sql Server SQLSRV30
PHP5.3连接SQL Server就不能用php_mssql.dll了. 网上下载了好多都不行,因为它的版本是5.2的,不能再PHP5.3中使用. 后来听说微软专门为PHP出了自己的dll. 叫做M ...
- 记录一下学习Android的小知识
目前要设计即时通讯的整体架构,包括服务端.Android.IOS.PC.平板等等系统,所以需要研究一下手机的实现方式,开始从Android入手,偶尔在这记录下小知识. ADT: 1.页面功能请求结构, ...
- WEB扫描器Atscan的安装和使用
项目地址:https://github.com/AlisamTechnology/ATSCAN root@sch01ar:/sch01ar# git clone https://github.com/ ...
- java成神之——正则表达式基本使用
正则表达式 常用匹配规则 基本使用 标记符的使用 部分正则标记 正则表达式在字符串方法中的使用 结语 正则表达式 常用匹配规则 [abc] abc其中一个 [^abc] abc之外的一个 [a-z] ...
- 第一章 初识MySQL(待续)
···········
- 「小程序JAVA实战」微信开发者工具helloworld(三)
转自:https://idig8.com/2018/08/09/xiaochengxu-chuji-03/ 第一个小程序demo的运行,首选需要去使用开发工具 开发工具下载安装 https://mp. ...
- Android 截屏检测
最近项目中新接到一个需求,对手机截屏进行检测并进行后续操作,类似于Snapchat,iOS具有先天优势,因iOS系统提供了相关API!Google无果之后原作者决定再次造轮子,为了持续表达对Rx的敬意 ...
- linux多线程默认栈大小和最大线程数
linux的线程栈大小可以使用ulimit -s查看,对于ubunt 2.6的内核线程栈的默认大小为8M,如下: shine@shine-bupt:~/Program/C$ ulimit -s 819 ...
- schedule和scheduleAtFixedRate的区别
- ubuntu网速慢解决方法
ubuntu网速慢解决方法 (2011-04-02 09:58:21) 本人在Window7下装ubuntu10.10双系统,在window7下速度挺快的,到了ubuntu速度就慢了很 ...