本文实例展示了DevExpress实现为TextEdit设置水印文字的方法,是一个很实用的技巧。分享给大家供大家参考。
转自 http://blog.csdn.net/yh0503/article/details/51487726
关键代码如下:
1 public static void SetWatermark(this TextEdit textEdit, string watermark) 2 { 3 textEdit.Properties.NullValuePromptShowForEmptyValue =true; 4 textEdit.Properties.NullValuePrompt = watermark; 5 } 6 public static void ClearWatermark(this TextEdit textEdit) 7 { 8 if(textEdit.Properties.NullValuePromptShowForEmptyValue) 9 textEdit.Properties.NullValuePrompt =string.Empty; 10 }
测试代码如下:
1 privatevoid Form1_Load(objectsender, EventArgs e) 2 { 3 textEdit1.SetWatermark("请输入用户名称...."); 4 textEdit2.SetWatermark("请输入用户密码...."); 5 } 6 7 privatevoid simpleButton1_Click(objectsender, EventArgs e) 8 { 9 textEdit1.ClearWatermark(); 10 textEdit2.ClearWatermark(); 11 }
代码效果如下图所示:
时间: 2024-11-06 09:29:44