[WinForm]为TextBox设置水印文字】的更多相关文章

关键代码: using System; using System.Runtime.InteropServices; using System.Windows.Forms; namespace WinFormUtilHelpV2 { /// <summary> /// 基于.NET 2.0的TextBox工具类 /// </summary> public static class TextBoxToolV2 { private const int EM_SETCUEBANNER =…
本文实例展示了DevExpress实现为TextEdit设置水印文字的方法,是一个很实用的技巧.分享给大家供大家参考. 转自 http://blog.csdn.net/yh0503/article/details/51487726 关键代码如下: public static void SetWatermark(this TextEdit textEdit, string watermark) { textEdit.Properties.NullValuePromptShowForEmptyVal…
winform的Textbox设置只读之后ForeColor无效. 通过以下方法就可以解决: 设置为只读之后,把BackColor改一下,然后运行一下窗口,再设置ForeColor就没问题了. tbText.ForeColor = Color.Red;tbText.BackColor = Color.White;//改变文本框的颜色 tbText.Text ="5";…
Winform给TextBox设置默认值(获取焦点后默认值消失) 主要是通过TextBox的获取焦点Enter和失去焦点Leave两个事件来实现的, 思路如下: 1.设置一个字符串常量,作为TextBox的默认值: 2.在界面的构造方法中将默认值赋值给TextBox,并设置TextBox的ForeColor为灰色: 3.编写获取焦点事件 TextBox_Enter(object sender, EventArgs e) ,判断TextBox的Text是否等于默认值, 是:则将TextBox内容清…
winform的Textbox设置只读之后设置ForeColor更改颜色无效.这是 TextBox 默认的行为. 解决方法:设置为只读之后,修改控件的BackColor,再设置ForeColor就可以了.…
设置水印代码: //设置水印值public static void SetWatermark(this TextEdit textEdit, string watermark) { textEdit.Properties.NullValuePromptShowForEmptyValue = true; textEdit.Properties.NullValuePrompt = watermark; } //清除水印值 public static void ClearWatermark(this…
主要是通过TextBox的获取焦点Enter和失去焦点Leave两个事件来实现的, 思路如下: 1.设置一个字符串常量,作为TextBox的默认值: 2.在界面的构造方法中将默认值赋值给TextBox,并设置TextBox的ForeColor为灰色: 3.编写获取焦点事件 TextBox_Enter(object sender, EventArgs e) ,判断TextBox的Text是否等于默认值, 是:则将TextBox内容清空,并将前景色ForeColor改成正常的颜色 4.失去焦点事件…
设置水印与消除水印 public static void SetWatermark(TextEdit textEdit, string watermark) { textEdit.Properties.NullValuePromptShowForEmptyValue =true; textEdit.Properties.NullValuePrompt = watermark; } public static void ClearWatermark(TextEdit textEdit) { if(…
#region TextBox 文本框水印文字 /// <summary> /// 基于.NET 2.0的TextBox工具类 /// </summary> public static class TextBoxToolV2 { private const int EM_SETCUEBANNER = 0x1501; [DllImport("user32.dll", CharSet = CharSet.Auto)] private static extern In…
  一.简单回顾 在前两节中,对Panel和GroupBox控件进行了相关的扩展应用,主要都是设置控件的边框以及边框颜色等.本节,继续对WinForm现有的控件TextBox进行扩展,来满足实际开发中的需要. 二.TextBox扩展 WinForm现有的TextBox控件功能已然相当强大了,但有些时候仍然不能满足一些实际开发的需要,本节针对开发中的需求问题,对控件进行了以下扩展: 1. 和以往一样,设置控件的边框问题,主要有:边框颜色.边框粗细: 2. 控件添加水印文字效果,可以设置水印文字颜色…