This entry has been published on 2019-04-11 and may be out of date.
Last Updated on 2019-04-11.
[:en]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:
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:
Reference[:]