Advertisement
Guest User

TextBoxWatermarkExtensionMethod

a guest
Feb 15th, 2012
1,474
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.76 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Runtime.InteropServices;
  6. using System.Windows.Forms;
  7.  
  8. namespace YourNameSpace
  9. {
  10.     public static class TextBoxWatermarkExtensionMethod
  11.     {
  12.         private const uint ECM_FIRST = 0x1500;
  13.         private const uint EM_SETCUEBANNER = ECM_FIRST + 1;
  14.  
  15.         [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
  16.         private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, uint wParam, [MarshalAs(UnmanagedType.LPWStr)] string lParam);
  17.  
  18.         public static void SetWatermark(this TextBox textBox, string watermarkText)
  19.         {
  20.             SendMessage(textBox.Handle, EM_SETCUEBANNER, 0, watermarkText);
  21.         }
  22.  
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement