zoukankan      html  css  js  c++  java
  • 自定义控件之带水印的Textbox

    代码地址:

    http://download.csdn.net/detail/u010312811/9553195

    Windows消息处理:

    http://www.cnblogs.com/imstrive/p/5596030.html

    1.私有变量

    1 //水印文字
    2 private string _waterText = String.Empty;
    3 //水印颜色
    4 private Color _waterColor = Color.DarkGray;

    2.属性

     1 /// <summary>
     2 /// 水印文字
     3 /// </summary>
     4 [Description("水印文字"),Category("SLT")]
     5 public string WaterText
     6 {
     7     get { return _waterText; }
     8     set { _waterText = value; }
     9 }
    10 /// <summary>
    11 /// 水印颜色
    12 /// </summary>
    13 [Description("水印文字"),Category("SLT")]
    14 public Color WaterColor
    15 {
    16     get { return _waterColor; }
    17     set { _waterColor = value; }
    18 }

    3.Override Methods

    1 protected override void WndProc(ref Message m)
    2 {
    3     base.WndProc(ref m);
    4 
    5     if (m.Msg == (int)WindowsMessage.WM_PAINT)
    6     {
    7         WmPaintWater(ref m);
    8     }
    9 }

    4.方法

     1 private void WmPaintWater(ref Message m)
     2 {
     3     //获取控件绑定到的窗口句柄
     4     using (Graphics g = Graphics.FromHwnd(base.Handle))
     5     {
     6         if (string.IsNullOrEmpty(this.Text) && !String.IsNullOrEmpty(this.WaterText) && !this.Focused)
     7         {
     8             TextFormatFlags flags = TextFormatFlags.EndEllipsis | TextFormatFlags.VerticalCenter;
     9             TextRenderer.DrawText(g, WaterText, this.Font, this.ClientRectangle, WaterColor, flags);
    10         }
    11     }
    12 }
  • 相关阅读:
    shell编程
    git
    Flask-SQLAlchemy
    pipreqs
    命令行操作flask
    SQLAlchemy中scoped_session实现线程安全
    打印信息
    键盘事件
    安卓手机APP压力monkey测试
    手机APP功能测试经验分享2016.06.06
  • 原文地址:https://www.cnblogs.com/imstrive/p/5596027.html
Copyright © 2011-2022 走看看