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