DevExpress 为TextEdit设置水印文字
设置水印代码:
//设置水印值
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; }
调用:
private void Form1_Load(object sender, EventArgs e) { textEdit1.SetWatermark("请输入用户名称...."); textEdit2.SetWatermark("请输入用户密码...."); }
private void simpleButton1_Click(object sender, EventArgs e)
{
textEdit1.ClearWatermark();
textEdit2.ClearWatermark();
}
效果图: