zoukankan      html  css  js  c++  java
  • Winform 水印TextBox

    public partial class WaterTextBox : TextBox
    {
        private readonly Label lblwaterText = new Label();
    
        public WaterTextBox()
        {
            InitializeComponent();
            lblwaterText.BorderStyle = BorderStyle.None;
            lblwaterText.Enabled = false;
            lblwaterText.BackColor = Color.White;
            lblwaterText.AutoSize = false;
            lblwaterText.Top = 1;
            lblwaterText.Left = 2;
            lblwaterText.FlatStyle = FlatStyle.System;
            Controls.Add(lblwaterText);
        }
    
        [Category("扩展属性"), Description("显示的提示信息")]
        public string WaterText
        {
            get { return lblwaterText.Text; }
            set { lblwaterText.Text = value; }
        }
    
        public override string Text
        {
            set
            {
                lblwaterText.Visible = value == string.Empty;
                base.Text = value;
            }
            get
            {
                return base.Text;
            }
        }
    
        protected override void OnSizeChanged(EventArgs e)
        {
            if (Multiline && (ScrollBars == ScrollBars.Vertical || ScrollBars == ScrollBars.Both))
                lblwaterText.Width = Width - 20;
            else
                lblwaterText.Width = Width;
            lblwaterText.Height = Height - 2;
            base.OnSizeChanged(e);
        }
    
        protected override void OnTextChanged(EventArgs e)
        {
            lblwaterText.Visible = base.Text == string.Empty;
            base.OnTextChanged(e);
        }
    
        protected override void OnMouseDown(MouseEventArgs e)
        {
            lblwaterText.Visible = false;
            base.OnMouseDown(e);
        }
    
        protected override void OnMouseLeave(EventArgs e)
        {
            lblwaterText.Visible = base.Text == string.Empty;
            base.OnMouseLeave(e);
        }
    
        //protected override void OnEnter(EventArgs e)
        //{
        //    lblwaterText.Visible = false;
        //    base.OnEnter(e);
        //}
    
        //protected override void OnLeave(EventArgs e)
        //{
        //    if (string.IsNullOrEmpty(base.Text))
        //        lblwaterText.Visible = true;
        //    base.OnLeave(e);
        //}
    }
  • 相关阅读:
    第七周-学习进度条
    《梦断代码》阅读笔记01
    第六周-学习进度条
    构建之法阅读笔记03
    结对项目开发(石家庄地铁乘车系统)
    第五周-学习进度条
    第四周-学习进度条
    HDU--1272 小希的迷宫(并查集判环与联通)
    HDU--1856 More is better(简单带权并查集)
    HDU--3635 带权并查集
  • 原文地址:https://www.cnblogs.com/luoqin520/p/4624766.html
Copyright © 2011-2022 走看看