• TextBox 文本框水印文字


     1     #region TextBox 文本框水印文字
     2     /// <summary>
     3     /// 基于.NET 2.0的TextBox工具类
     4     /// </summary>
     5     public static class TextBoxToolV2 {
     6         private const int EM_SETCUEBANNER = 0x1501;
     7         [DllImport("user32.dll", CharSet = CharSet.Auto)]
     8 
     9         private static extern Int32 SendMessage
    10          (IntPtr hWnd, int msg, int wParam, [MarshalAs(UnmanagedType.LPWStr)] string lParam);
    11 
    12         /// <summary>
    13         /// 为TextBox设置水印文字
    14         /// </summary>
    15         /// <param name="textBox">TextBox</param>
    16         /// <param name="watermark">水印文字</param>
    17         public static void SetWatermark(this TextBox textBox, string watermark) {
    18             SendMessage(textBox.Handle, EM_SETCUEBANNER, 0, watermark);
    19         }
    20         /// <summary>
    21         /// 清除水印文字
    22         /// </summary>
    23         /// <param name="textBox">TextBox</param>
    24         public static void ClearWatermark(this TextBox textBox) {
    25             SendMessage(textBox.Handle, EM_SETCUEBANNER, 0, string.Empty);
    26         }
    27     }
    28     
    29     #endregion
  • 相关阅读:
    64_q2
    64_q1
    64_p10
    64_p9
    64_p8
    64_p7
    64_p6
    64_p5
    64_p4
    64_p3
  • 原文地址:https://www.cnblogs.com/lyl6796910/p/5213381.html
Copyright © 2020-2023  润新知