亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

WinForm實(shí)現(xiàn)為T(mén)extBox設(shè)置水印文字功能

 更新時(shí)間:2014年08月19日 17:15:12   投稿:shichen2014  
這篇文章主要介紹了WinForm實(shí)現(xiàn)為T(mén)extBox設(shè)置水印文字功能,很實(shí)用的一個(gè)技巧,需要的朋友可以參考下

本文實(shí)例展示了WinForm實(shí)現(xiàn)為T(mén)extBox設(shè)置水印文字功能,非常實(shí)用的技巧,分享給大家供大家參考。

關(guān)鍵代碼如下:

using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace WinFormUtilHelpV2
{
  /// <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>
    /// 為T(mén)extBox設(shè)置水印文字
    /// </summary>
    /// <param name="textBox">TextBox</param>
    /// <param name="watermark">水印文字</param>
    public static void SetWatermark(this TextBox textBox, string watermark)
    {
      SendMessage(textBox.Handle, EM_SETCUEBANNER, 0, watermark);
    }
    /// <summary>
    /// 清除水印文字
    /// </summary>
    /// <param name="textBox">TextBox</param>
    public static void ClearWatermark(this TextBox textBox)
    {
      SendMessage(textBox.Handle, EM_SETCUEBANNER, 0, string.Empty);
    }
  }
}

測(cè)試代碼如下:

using System;
using System.Windows.Forms;
using WinFormUtilHelpV2;

namespace WinFormUtilHelpV2Test
{
  public partial class WinTextBoxToolV2Test : Form
  {
    public WinTextBoxToolV2Test()
    {
      InitializeComponent();
    }

    private void WinTextBoxToolV2Test_Load(object sender, EventArgs e)
    {
      textBox1.SetWatermark("請(qǐng)輸入用戶名稱....");
      textBox2.SetWatermark("請(qǐng)輸入用戶密碼....");
    }

    private void button1_Click(object sender, EventArgs e)
    {
      textBox1.ClearWatermark();
      textBox2.ClearWatermark();
    }
  }
}

測(cè)試效果如下圖所示:

希望本文所述的為T(mén)extBox設(shè)置水印文字功能示例對(duì)大家C#程序設(shè)計(jì)有所幫助!

相關(guān)文章

最新評(píng)論