WinForm 自定义控件TextBox问题
我写了一个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;
}
}
}
--------------------编程问答-------------------- 但是不知道为什么只要把改空间的内容全部删除时
说得不清楚
我猜测:
因为你的程序里已经使用了MyRegexTextBox的方法啊属性啊
如果你删除了,那当然会报错啊
--------------------编程问答-------------------- 报的什么错啊? --------------------编程问答-------------------- 应该是别处用到了这个控件吧,为什么要删除呢,也可以隐藏的吧? --------------------编程问答-------------------- 针对这样的问题告诉你一个很笨、但是很有效的办法,就是把所有可能出错的代码注释掉,然后再一点点去掉注释,一遍遍调试,直到再次出现错误。很容易找到问题出在哪里。 --------------------编程问答-------------------- 进行调试,设置断点,找到问题的所在...
补充:.NET技术 , C#