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;
        }
    }
}