0

I need to have a watermark on both of my form using 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);
        }
    }

I tried to use this to both form but I got an error saying

"Ambiguity between namespace.TextBoxWatermarkExtensionMethod.ECM_FIRST and namespace.TextBoxWatermarkExtensionMethod.ECM_FIRST."

I think this class must not duplicate. But how to call it between the two form.

2
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by Momerath
0

You call it like you would any class method of the class it extends. Since it is extending TextBox you'd just use myTextBox.SetWatermark("My text");

This topic has been dead for over six months. 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.