C#(WINFROM)实现textbox中输入值时显示提示框

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace KSpring.Component.DGVForEdit.TextBoxForDGV
{
    public class TextBoxForDGV : TextBox
    {
        private ToolTip toolTip1;

        private System.ComponentModel.IContainer components;

        string _tempStr = "请输入";

        public TextBoxForDGV()
        {
            InitializeComponent();
            this.Enter += new EventHandler(TextBoxForDGV_Enter);
            this.TextChanged += new EventHandler(TextBoxForDGV_TextChanged);
            this.Leave += new EventHandler(TextBoxForDGV_Leave);
        }

        void TextBoxForDGV_Leave(object sender, EventArgs e)
        {
            this.toolTip1.Hide(this);
        }

        void TextBoxForDGV_TextChanged(object sender, EventArgs e)
        {
            int _i = 0;
            if (int.TryParse(Text, out _i) == false)
            {
                _tempStr = "不是数字";
            }
            else
            {
                if (Text.Trim().Length != 10)
                {
                    _tempStr = "你输入了" + Text.Trim().Length + "位,还差" + (10 - Text.Trim().Length);
                }
                else
                {
                    _tempStr = "输入正确";
                }
            }

            this.toolTip1.Show(_tempStr, this);
        }

        void TextBoxForDGV_Enter(object sender, EventArgs e)
        {
            this.toolTip1.Show(_tempStr, this);
        }

        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
            this.SuspendLayout();
            //
            // toolTip1
            //
            this.toolTip1.ShowAlways = true;
            this.ResumeLayout(false);

        }

        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
        }

    }
}

转载于:https://www.cnblogs.com/liruiba/archive/2009/05/05/1450121.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值