DevExpress文本编辑类控件设置水印

为TextEdit增加水印

public static class TextEditHelper
{
    //设置水印值
    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;
    }
}
  • 上边的方法不仅适用于TextEdit,只要是文本输入类得控件都可以使用,如ComboBoxEdit、lookUpEdit等,因为其Properties属性都继承于RepositoryItemTextEdit基类

posted @ 2022-11-30 15:53  北有高楼233  阅读(238)  评论(0)    收藏  举报