DevExpress实现为TextEdit设置水印文字的方法
设置水印与消除水印
public static void SetWatermark(TextEdit textEdit, string watermark) { textEdit.Properties.NullValuePromptShowForEmptyValue =true; textEdit.Properties.NullValuePrompt = watermark; } public static void ClearWatermark(TextEdit textEdit) { if(textEdit.Properties.NullValuePromptShowForEmptyValue) textEdit.Properties.NullValuePrompt =string.Empty; }
测试代码
privatevoid Form1_Load(objectsender, EventArgs e) { SetWatermark(textEdit1, "请输入用户名称...."); SetWatermark(textEdit2, "请输入用户密码...."); } privatevoid simpleButton1_Click(objectsender, EventArgs e) { ClearWatermark(textEdit1); ClearWatermark(textEdit2); }