我想使用c#在Windows Form的文本框中使用水印?
我在stackoverflow中找到了this link。但是我真的不知道如何在我的windows应用程序中使用。
class WatermarkTextBox : TextBox
{
    private const uint ECM_FIRST = 0x1500;
    private const uint EM_SETCUEBANNER = ECM_FIRST + 1;
    [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
    static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, uint wParam, [MarshalAs(UnmanagedType.LPWStr)] string lParam);
    private string watermarkText;
    public string WatermarkText
    {
        get { return watermarkText; }
        set
        {
            watermarkText = value;
            SetWatermark(watermarkText);
        }
    }
    private void SetWatermark(string watermarkText)
    {
        SendMessage(this.Handle, EM_SETCUEBANNER, 0, watermarkText);
    }       
}请帮助如何使用SendMessage方法或建议我任何其他(容易)的方式使用水印。
发布于 2013-07-19 18:47:51
SetWatermark是TextBox上的一个扩展方法,因此在添加了WatermarkTextBox类的名称空间中的任何位置,都可以使用SetWatermark方法来传递要应用于TextBox的水印字符串,如下所示:
`myTextBox.SetWatermark("your water mark text here");`在设计器中,SetWatermark不会作为TextBox的公共属性可见,但从您的代码中可以访问它,就像TextBox对象的任何bult-in方法一样。
https://stackoverflow.com/questions/5302242
复制相似问题