最新消息:ww12345678 的部落格重装上线,希望大家继续支持。

set WaterMark on textbox c# AX POS

网络文摘 William 603浏览 0评论

extension method :

public static class TextBoxWatermarkExtensionMethod
{
     private const uint ECM_FIRST = 0x1500;
     private const uint EM_SETCUEBANNER = ECM_FIRST + 1;

     [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
     private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, uint wParam, [MarshalAs(UnmanagedType.LPWStr)] string lParam);

     public static void SetWatermark(this TextBox textBox, string watermarkText)
     {
        SendMessage(textBox.Handle, EM_SETCUEBANNER, 0, watermarkText);
     }
}

how to use it example on form constructor :

public TIDFrmIDSKirimUang()
{
     InitializeComponent();

     TextBoxWatermarkExtensionMethod.SetWatermark(txtTNoHP,"0815xxxxxxx");
     TextBoxWatermarkExtensionMethod.SetWatermark(txtNoHP,"0815xxxxxxx");
}

reference :
http://vidmar.net/weblog/archive/2008/11/05/watermarked-textbox-in-windows-forms-on-.net.aspx


发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址