Useful snippet for adding a placeholder text feature to a common Windows Forms TextBox like you might know it from HTML’s <input> tag.
Add e.g. to your ExtensionMethods:
1 2 3 4 5 6 7 8 |
private const int EM_SETCUEBANNER = 0x1501; [DllImport("user32.dll", CharSet = CharSet.Auto)] private static extern Int32 SendMessage(IntPtr hWnd, int msg, int wParam, [MarshalAs(UnmanagedType.LPWStr)]string lParam); public static void SetPlaceholder(this TextBox box, string text) { SendMessage(box.Handle, EM_SETCUEBANNER, 0, text); } |
Result:
Comments