zoukankan      html  css  js  c++  java
  • 简单的水印输入框

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Shapes;
    
    namespace WisHotel
    {
        public class WaterMarkBox : TextBox
        {
            #region MaskText
            /// <summary>
            /// view sort style, desc arrow
            /// </summary>
            public static readonly DependencyProperty MaskTextProperty = DependencyProperty.Register("MaskText", typeof(string), typeof(WaterMarkBox));
    
            public string MaskText
            {
                get { return (string)GetValue(MaskTextProperty); }
                set { SetValue(MaskTextProperty, value); }
            }
            #endregion
    
            public WaterMarkBox()
            {
                Loaded += (sender, args) =>
                    {
                        if (string.IsNullOrEmpty(base.Text))
                        {
                            base.Text = MaskText;
                            base.Foreground = Brushes.Gray;
                        }
                    };
    
                base.GotFocus += (sender, args) =>
                {
                    base.Foreground = Brushes.Black;
                    if (base.Text == MaskText)
                        base.Text = string.Empty;
                };
                base.LostFocus += (sender, args) =>
                {
                    if (!string.IsNullOrEmpty(base.Text))
                        return;
    
                    base.Text = MaskText;
                    base.Foreground = Brushes.Gray;
                };
            }
    
            public new string Text
            {
                get
                {
                    if (base.Text == MaskText)
                        return string.Empty;
                    else
                        return base.Text;
                }
                set { base.Text = value; }
            }
        }
    
    }
    <btn:WaterMarkBox Width="150" Height="20" MaskText="输入想要查找的房号..."/>
  • 相关阅读:
    I/O多路复用一些概念
    事件驱动模型
    协程-遇到I/O自动切换
    进程间共享数据Manager
    协程
    进程池
    Linux rpm 命令参数使用详解[介绍和应用]
    linux 增加用户 useradd 用法小结及配置文件说明
    java classpath批量设置shell脚本
    bat批处理设置Java JDK系统环境变量文件
  • 原文地址:https://www.cnblogs.com/Events/p/3752868.html
Copyright © 2011-2022 走看看