WinForm實(shí)現(xiàn)為T(mén)extBox設(shè)置水印文字功能
本文實(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ì)有所幫助!
- C#實(shí)現(xiàn)winform中RichTextBox在指定光標(biāo)位置插入圖片的方法
- 學(xué)習(xí)Winform文本類控件(Label、Button、TextBox)
- C# Winform使用擴(kuò)展方法實(shí)現(xiàn)自定義富文本框(RichTextBox)字體顏色
- C#中winform控制textbox輸入只能為數(shù)字的方法
- WinForm下 TextBox只允許輸入數(shù)字的小例子
- Winform之TextBox輸入日期格式驗(yàn)證yyyy-mm-dd
- Winform項(xiàng)目中TextBox控件DataBindings屬性
相關(guān)文章
Unity3D實(shí)現(xiàn)NavMesh導(dǎo)航網(wǎng)格尋路
這篇文章主要為大家詳細(xì)介紹了Unity3D實(shí)現(xiàn)NavMesh導(dǎo)航網(wǎng)格尋路,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-05-05c#獲得目標(biāo)服務(wù)器中所有數(shù)據(jù)庫(kù)名、表名、列名的實(shí)現(xiàn)代碼
這篇文章主要介紹了c#獲得目標(biāo)服務(wù)器中所有數(shù)據(jù)庫(kù)名、表名、列名的方法,需要的朋友可以參考下2014-05-05unity實(shí)現(xiàn)簡(jiǎn)單計(jì)算器
這篇文章主要為大家詳細(xì)介紹了unity實(shí)現(xiàn)簡(jiǎn)單計(jì)算器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-08-08C#?Random類隨機(jī)函數(shù)實(shí)例詳解
這篇文章主要為大家介紹了C#?Random類隨機(jī)函數(shù)實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-08-08基于WPF實(shí)現(xiàn)一個(gè)簡(jiǎn)單的音頻播放動(dòng)畫(huà)控件
這篇文章主要介紹了如何利用WPF實(shí)現(xiàn)一個(gè)簡(jiǎn)單的音頻播放動(dòng)畫(huà)控件,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)或工作有一定幫助,需要的可以參考一下2022-07-07在c#中使用servicestackredis操作redis的實(shí)例代碼
本篇文章主要介紹了在c#中使用servicestackredis操作redis的實(shí)例代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06