#region TextBox 文本框水印文字
/// <summary>
/// 基于.NET 2.0的TextBox工具类
/// </summary>
public static class TextBoxToolV2 {
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); /// <summary>
/// 为TextBox设置水印文字
/// </summary>
/// <param name="textBox">TextBox</param>
/// <param name="watermark">水印文字</param>
public static void SetWatermark(this TextBox textBox, string watermark) {
SendMessage(textBox.Handle, EM_SETCUEBANNER, , watermark);
}
/// <summary>
/// 清除水印文字
/// </summary>
/// <param name="textBox">TextBox</param>
public static void ClearWatermark(this TextBox textBox) {
SendMessage(textBox.Handle, EM_SETCUEBANNER, , string.Empty);
}
} #endregion
05-04 02:32