0

I read some articles with regards on watermarks in windows app, but I found it to be quite complicated. What is the best way to implement watermark in textboxes?

2
Contributors
9
Replies
10
Views
6 Years
Discussion Span
Last Post by Momerath
Featured Replies
  • 1

    Add this:[code]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, … Read More

  • 1

    [QUOTE=AngelicOne;1478697]I've fixed it! Thanks![/QUOTE] Just wanted to say 'code behind' is an ASP.NET term :) Read More

1

Add this:

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);
    }
}

After that you can do this:

myTextbox.SetWatermark("This is the watermark");
Comments
thanks
0

Hello, i'm sorry if this is late but where could I call the watermark class for my textbox? Tried in my form's load event but it's not present.

0

That code works for winforms applications, not ASP.NET. To watermark on ASP you'll have to use javascript, if it's possible.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.