qtextbox.cs

来自「基于C/S的医疗卫生管理系统」· CS 代码 · 共 95 行

CS
95
字号
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Drawing;

namespace Qeb.Control
{
    public partial class QTextBox : System.Windows.Forms.TextBox
    {
        private string m_LookUpPrompt = "";

        private Color oldColor = Color.Black;
        public QTextBox()
        {
            InitializeComponent();
            oldColor = this.ForeColor;
        }

        public QTextBox(IContainer container)
        {
            container.Add(this);

            InitializeComponent();

            oldColor = this.ForeColor;
        }

        /// <summary>
        /// 快速定位提示
        /// </summary>
        [Description("快速定位提示"), Category("自定义属性")]
        public string LoopUpPrompt
        {
            get { return m_LookUpPrompt; }
            set
            {
                if (value == null || value == "")
                {
                    m_LookUpPrompt = "";
                    this.SetLookUpPrompt(false);
                }
                else
                {
                    m_LookUpPrompt = value;
                    if (!this.Focused)
                    {
                        SetLookUpPrompt(true);
                    }
                }
            }
        }
        private void SetLookUpPrompt(bool show)
        {
            if (show)
            {
                this.Text = this.m_LookUpPrompt;
                this.ForeColor = Color.Silver;
            }
            else
            {
                if (this.Text == this.m_LookUpPrompt)
                {
                    this.ForeColor = oldColor;
                    this.Text = "";
                }
            }
        }
        protected override void OnEnter(EventArgs e)
        {
            base.OnEnter(e);
            if (this.m_LookUpPrompt != "" && this.Text == this.m_LookUpPrompt)
            {
                this.SetLookUpPrompt(false);
            }
        }

        protected override void OnLeave(EventArgs e)
        {
            base.OnLeave(e);
            if (this.m_LookUpPrompt != "" && this.Text == "")
            {
                this.SetLookUpPrompt(true);
            }
        }

        protected override void OnTextChanged(EventArgs e)
        {
            if (this.m_LookUpPrompt == "")                
                base.OnTextChanged(e);
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?