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中自定义搜索框(水印、清空按钮、加载中图标)的更多相关文章

  1. 使用Bootstrap3和Ladda UI实现的多种按钮“加载中”效果体验

    在线演示 在线演示 大家在开发基于web的网站或者web应用中,常常在AJAX调用的过程中需要提示用户并且展示相关的“加载中”效果,类似的UI设计也非常多,比如,当点击一个按钮后,在它的旁边显示一个 ...

  2. WPF实用指南一:在WPF窗体的边框中添加搜索框和按钮

    原文:WPF实用指南一:在WPF窗体的边框中添加搜索框和按钮 在边框中加入一些元素,在应用程序的界面设计中,已经开始流行起来.特别是在浏览器(Crome,IE,Firefox,Opera)中都有应用. ...

  3. bootStrap-table服务器端后台分页的使用,以及自定义搜索框的实现,前端代码到数据查询超详细讲解

    关于分页,之前一直纯手写js代码来实现,最近又需要用到分页,找了好多最终确定bootstrap-table,正好前端页面用的是bootstrap. 首先下载BootStrap-table的js和CSS ...

  4. iOS开发UI篇 -- UISearchBar 属性、方法详解及应用(自定义搜索框样式)

    很多APP都会涉及到搜索框,苹果也为我们提供了默认的搜索框UISearchBar.但实际项目中我们通常需要更改系统默认搜索框的样式.为了实现这一目标,我们需要先搞懂 UISearchBar 的属性及方 ...

  5. extjs在窗体中添加搜索框

    在extjs中添加搜索框,搜索框代码如下: this.searchField = new Ext.ux.form.SearchField({            store : this.store ...

  6. Qt之自定义搜索框

    简述 关于搜索框,大家都经常接触.例如:浏览器搜索.Windows资源管理器搜索等. 当然,这些对于Qt实现来说毫无压力,只要思路清晰,分分钟搞定. 方案一:调用QLineEdit现有接口 void ...

  7. 【Qt】Qt之自定义搜索框【转】

    简述 关于搜索框,大家都经常接触.例如:浏览器搜索.Windows资源管理器搜索等. 当然,这些对于Qt实现来说毫无压力,只要思路清晰,分分钟搞定. 简述 效果 细节分析 Coding 源码下载 效果 ...

  8. Qt之自定义搜索框——QLineEdit里增加一个Layout,还不影响正常输入文字(好像是一种比较通吃的方法)

    简述 关于搜索框,大家都经常接触.例如:浏览器搜索.Windows资源管理器搜索等. 当然,这些对于Qt实现来说毫无压力,只要思路清晰,分分钟搞定. 方案一:调用QLineEdit现有接口 void ...

  9. Android自定义View——自定义搜索框(SearchView)

    Android自定义View——自定义搜索框(SearchView) http://www.apkbus.com/android-142064-1-1.html

随机推荐

  1. Oracle 11g r2 rac +openfiler 2.99 安装

    1 openfiler 2.99 安装 在官网下载iso文件,这里选择openfileresa-2.99.1-x86_64-disc1.iso 版本,在vbox下创建一个虚拟机 --vbox 选择li ...

  2. winfrom绘制渐变 / 调用浏览器访问指定地址

    private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) {//绘制渐变色背景 Graphics g ...

  3. Informatica PowerCenter下载地址

    https://edelivery.oracle.com/EPD/Download/get_form?egroup_aru_number=12854075

  4. Flask之性能

    5.5 性能 一.不同角度的网站性能 普通用户认为的网站性能 网站性能对于普通用户来说,最直接的体现就是响应时间.用户在浏览器上直观感受到的网站响应速度,即从客户端发送请求,到服务器返回响应内容的时间 ...

  5. Angular-cli新建项目目录结构详解

    Angular-cli新建项目目录结构详解 在上一篇博客中我们已经通过Angular CLI命令行工具创建出来一个全新的Angular项目,要想写项目,首先我们要先搞清楚项目的目录结构是怎样的,每个文 ...

  6. spring mvc default-servlet mvc:resources mvc:default-servlet-handler区别

    mvc:default-servlet-handler其实就是default-servlet 交由web容器自己处理 mvc:resources spring来处理 没有被映射的url web容器来处 ...

  7. C51串口的SCON寄存器及工作…

    原文地址:C51串口的SCON寄存器及工作方式作者:batistar 一,串行口控制寄存器SCON 它用于定义串行口的工作方式及实施接收和发送控制.字节地址为98H,其各位定义如下表: D7 D6 D ...

  8. SpringMVC简单的文件上传

    引入依赖包: <!-- 文件上传的依赖 --> <dependency> <groupId>commons-fileupload</groupId> & ...

  9. hdu3530 Subsequence

    题意:There is a sequence of integers. Your task is to find the longest subsequence that satisfies the ...

  10. 【bzoj2947】[Poi2000]促销

    2947: [Poi2000]促销 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 181  Solved: 120[Submit][Status][D ...