win32api之添加水印

不多说,直接上代码。

public class Watermark
{
    private const int EM_SETCUEBANNER = 0x1501;

    /// <summary>
    /// 设置水印.
    /// </summary>
    /// <param name="handle">The handle.</param>
    /// <param name="watermark">The watermark.</param>
    /// <author>YangSen</author>
    public static void SetValue(IntPtr handle, string watermark)
    {
        Methods.SendMessage(handle, EM_SETCUEBANNER, 0, watermark);
    }

    /// <summary>
    /// 清楚水印.
    /// </summary>
    /// <param name="handle">The handle.</param>
    /// <author>YangSen</author>
    public static void Clear(IntPtr handle)
    {
        Methods.SendMessage(handle, EM_SETCUEBANNER, 0, string.Empty);
    }
}
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, uint wParam, [MarshalAs(UnmanagedType.LPWStr)] string lParam);

设置水印的效果我这里就不多说了,有兴趣的朋友可以试一下。适合编辑类的控件。

猜你喜欢

转载自blog.csdn.net/yangsen600/article/details/56280022