首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

只好输入int数字的文本控件

2012-12-23 
只能输入int数字的文本控件using Systemusing System.Collections.Genericusing System.ComponentModel

只能输入int数字的文本控件

using System;using System.Collections.Generic;using System.ComponentModel;using System.Drawing;using System.Data;using System.Text;using System.Windows.Forms;namespace Renters.UI{    public partial class txtIntBox : UserControl    {        public txtIntBox()        {            InitializeComponent();        }        /// 时间:2007-8-20        /// 修改:CAKEBIRD        /// 功能:用户控件实现对text只能输入int型数字的控制        /// 更新记录        /// 时间:2007-8-29         /// 修改功能:增加数据大于0判断        public string txt_Text        {            get            {                return this.textBox1.Text.Trim().ToString();            }            set            {                this.textBox1.Text = value;            }        }        //文本框的ReadOnly属性        public bool ReadOnly        {            get            {                return this.textBox1.ReadOnly;            }            set            {                this.textBox1.ReadOnly = value;            }        }        private void textBox1_TextChanged(object sender, EventArgs e)        {                       string txt = textBox1.Text.ToString();            if (txt != "")            {                if (tbchange(txt))                {                }                else                {                    textBox1.Text = txt.Remove(txt.Length - 1);                    textBox1.Select(textBox1.Text.Length, 0);                }            }                    }                private bool tbchange(string txt)        {            try            {                                double  i = System.Int32.Parse(txt);                if (i < 0)                {                    return false;                }                return true;            }            catch             {                return false;                            }        }        private void txtIntBox_Load(object sender, EventArgs e)        {            textBox1.Width = this.Size.Width;        }    }}

热点排行