3C科技 娛樂遊戲 美食旅遊 時尚美妝 親子育兒 生活休閒 金融理財 健康運動 寰宇綜合

Zi 字媒體

2017-07-25T20:27:27+00:00
加入好友
[C#] TextBox做浮水印提示(提示文字)   資料來源:https://dotblogs.com.tw/sam319/2010/01/19/13106       public partial class uTextBox : TextBox     {         private string _tipText = string.Empty; //提示訊息         public string TipText         {             get { return _tipText; }             set { _tipText = value; Invalidate(); }         }         private Color _tipColor = SystemColors.Highlight; //訊息顏色         public Color TipColor         {             get { return _tipColor; }             set { _tipColor = value; Invalidate(); }         }         private Font _tipFont = DefaultFont; //訊息字型         public Font TipFont         {             get { return _tipFont; }             set { _tipFont = value; Invalidate(); }         }         const int WM_PAINT = 0xF; //繪製的訊息         protected override void WndProc(ref Message m)         {             base.WndProc(ref m);             if (m.Msg == WM_PAINT && !string.IsNullOrEmpty(_tipText) && Text.Length == 0 && Enabled && !ReadOnly && !Focused) //判斷TextBox的狀態決定要不要顯示提示訊息             {                 TextFormatFlags formatFlags = TextFormatFlags.Default; //使用原始設定的對齊方式來顯示提示訊息                 switch (TextAlign)                 {                     case HorizontalAlignment.Center:                         formatFlags = TextFormatFlags.HorizontalCenter;                         break;                     case HorizontalAlignment.Left:                         formatFlags = TextFormatFlags.Left;                         break;                     case HorizontalAlignment.Right:                         formatFlags = TextFormatFlags.Right;                         break;                 }                 TextRenderer.DrawText(Graphics.FromHwnd(Handle), _tipText, _tipFont, ClientRectangle, _tipColor, BackColor, formatFlags); //畫出提示訊息             }         }         public uTextBox()         {                      }     }      

本文由jashliaoeuwordpress提供 原文連結

寫了 5860316篇文章,獲得 23313次喜歡
精彩推薦