winform的水印TextBox
public partial class WaterTextBox : TextBox
{
private readonly Label lblwaterText = new Label(); public WaterTextBox()
{
InitializeComponent();
lblwaterText.BorderStyle = BorderStyle.None;
lblwaterText.Enabled = false;
lblwaterText.BackColor = Color.White;
lblwaterText.AutoSize = false;
lblwaterText.Top = 1;
lblwaterText.Left = 2;
lblwaterText.FlatStyle = FlatStyle.System;
Controls.Add(lblwaterText);
} [Category("扩展属性"), Description("显示的提示信息")]
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 - 20;
else
lblwaterText.Width = Width;
lblwaterText.Height = Height - 2;
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);
} //protected override void OnEnter(EventArgs e)
//{
// lblwaterText.Visible = false;
// base.OnEnter(e);
//} //protected override void OnLeave(EventArgs e)
//{
// if (string.IsNullOrEmpty(base.Text))
// lblwaterText.Visible = true;
// base.OnLeave(e);
//}
winform的水印TextBox的更多相关文章
- WinForm 换行问题 textbox (转)
WinForm 换行问题 textbox 今天碰到一段string在label中能正常换行,但是在textbox中却无法换行的问题. 首先考虑是换行符的问题.在网上查了些资料: 1.TextBox 中 ...
- C#的winform中控制TextBox中只能输入数字
C#的winform中控制TextBox中只能输入数字 private void textBox3_KeyPress(object sender, System.Windows.Forms.KeyPr ...
- C# textbox中输入时加限制条件 // C#Winform下限制TextBox只能输入数字 // 才疏学浅(TextBox 小数点不能在首位+只能输入数字)
textbox中输入时加限制条件 分类: C# winform2008-08-26 08:30 306人阅读 评论(0) 收藏 举报 textbox正则表达式object 1.用正则表达式! 2.使用 ...
- Winform 水印TextBox
方法一: public partial class WaterTextBox : TextBox { private readonly Label lblwaterText = new Label() ...
- windows phone 水印TextBox
原文来自:wp教程网 原理:在失去焦点和获取焦点的时候,判断Text值是否为空或者是否与水印值相同,然后修改TextBox中的Text和Foreground. 代码如下: /* =========== ...
- C#在Winform中改变Textbox高度三种方法
最近在做C# Winform项目,需要有一个能动态调整大小的Textbox,并且要是单行的.试了几次,单行模式的Textbox不能直接改高度.于是搜索了一下,整理出几个改变高度的方法. 1.将Text ...
- WinForm中当TextBox重新获得焦点时输入法失效问题
在winform 中,每当TextBox获得焦点时,部分输入法会失效(如智能ABC.五笔98.极品五笔等),需要重新切换输入法才能正常使用. 此时要将Form的ImeMode属性改为:OnHalf(或 ...
- WPF 水印TextBox WatermarkTextBox
//https://blog.csdn.net/puchitomato/article/details/12248691 转自以上链接,自己添加了Enter响应事件. public class ...
- Winform中的TextBox的小技巧
1 一些常用属性this.textBox5.PasswordChar = '@'; //密码的样式 this.textBox5.UseSystemPasswordChar = ...
随机推荐
- 十一、移植优化---CONFIG 优化进 menuconfig(1)
在移植 JZ2440 中,include/configs/jz2440.h 中有很多config 项都是已经在 uboot 的主配置中已经存在了的,这些配置造成了重复,需要优化. 先将原先的 smdk ...
- Linux centos 防火墙篇
防火墙的关闭 service iptables stop 永久关闭 chkconfug iptables off 查看状态 service iptables status
- Debian Security Advisory(Debian安全报告) DSA-4411-1 firefox-esr security update
Debian Security Advisory(Debian安全报告) DSA-4411-1 firefox-esr security update Package :firefox-esr CV ...
- c语言 弹弹球小游戏
#include <stdio.h>#include <stdlib.h>#include <windows.h>#include <time.h>#i ...
- 第20月第4天 pycharm utf-8
1.运行python %run a.py 运行 https://blog.csdn.net/little_bobo/article/details/78982412 2.UnicodeDecodeEr ...
- A - Piece of Cake Kattis - pieceofcake (数学)
题目链接: A - Piece of Cake Kattis - pieceofcake 题目大意:给你一个多边形,然后给你这个多边形的每个点的坐标,让你从这个n个点中选出k个点,问这个k个点形成的面 ...
- MongoDB 学习手册 - 安装(windwos 环境)
- 经典视觉SLAM框架
经典视觉SLAM框架 整个视觉SLAM流程包括以下步骤: 1. 传感器信息读取.在视觉SLAM中主要为相机图像信息的读取和预处理. 2. 视觉里程计(Visual Odometry,VO).视觉里程计 ...
- 阿里云ECS centos7配置tomcat
准备:创建好developer目录和tomcat子目录 1.在 http://tomcat.apache.org/download-80.cgi 下载tomcat,通过Xftp拷贝到tomcat目录 ...
- Springboot 配置 ssl 实现HTTPS 请求 & Tomcat配置SSL支持https请求
SSL(Secure Sockets Layer 安全套接层),及其继任者传输层安全(Transport Layer Security,TLS)是为网络通信提供安全及数据完整性的一种安全协议.TLS与 ...