我写了一个TextBox控件,但是不知道为什么只要把改空间的内容全部删除时,程序就会出异常,但是我实在找不到这个问题在哪里,请高手能帮帮我,分实在是不够啊using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace RiskAssessmentUserControl
{
    public class MyRegexTextBox : TextBox
    {
        private double m_dMinValue = 0;
        private double m_dMaxValue = 0;
        private bool m_bIsIncludeMin = false;
        private bool m_bIsIncludeMax = false;
        private bool m_bIsSuportRange = false;        public MyRegexTextBox()
        {
            //this.KeyPress += new KeyPressEventHandler(MyRegexTextBox_KeyPress);
            //this.Leave += new EventHandler(MyRegexTextBox_Leave);
        }        void MyRegexTextBox_Leave(object sender, EventArgs e)
        {
            if (!IsConfromRange(Double.Parse(this.Text)))
            {
                this.Text = string.Empty;
                string errorLeft = ">";
                string errorRight = "<";
                if (m_bIsIncludeMin == true)
                {
                    errorLeft = "≥";
                }
                if (m_bIsIncludeMax == true)
                {
                    errorRight = "≤";
                }
                if (MessageBox.Show("请输入" + errorLeft + m_dMinValue.ToString() + "且" + errorRight + m_dMaxValue.ToString() + "的数字", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error) == DialogResult.OK)
                {
                    this.Clear();
                    this.Focus();
                    MessageBox.Show("请输入" + errorLeft + m_dMinValue.ToString() + "且" + errorRight + m_dMinValue.ToString() + "的数字");  
                }
            }
        }        void MyRegexTextBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!Char.IsNumber(e.KeyChar) && !Char.IsPunctuation(e.KeyChar) && !Char.IsControl(e.KeyChar))
            {
                e.Handled = true;
            }
            else if (Char.IsPunctuation(e.KeyChar))
            {
                if (e.KeyChar == '.')
                {
                    if (((TextBox)sender).Text.LastIndexOf('.') != -1)
                    {
                        e.Handled = true;
                    }
                    else
                    {
                        
                    }
                }
                else
                {
                    e.Handled = true;
                }
            }
        }        private bool IsConfromRange(double _value)
        {
            return true;
            if (m_bIsSuportRange == false)
            {
                return true;
            }
            else
            {
                if (_value < m_dMinValue || _value > m_dMaxValue)
                {
                    return false;
                }
                else if (_value == m_dMinValue && m_bIsIncludeMin == false)
                {
                    return false;
                }
                else if (_value == m_dMaxValue && m_bIsIncludeMax == false)
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
        }        public void SetRange(double _Min, double _Max, bool _isIncludeMin, bool _isIncludeMax)
        {
            return;
            m_bIsSuportRange = true;
            m_dMinValue = _Min;
            m_dMaxValue = _Max;
            m_bIsIncludeMin = _isIncludeMin;
            m_bIsIncludeMax = _isIncludeMax;
        }
    }
}