我写了一个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;
}
}
}
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;
}
}
}
解决方案 »
- c#编写程序,实现双击文件名得到该文件的路径
- c# 如何通过数据源绑定到新的数据成员?
- 为什么同样的数据库连结语句在windows 窗体可运行,在ASP.NET下去显示用户 'NT AUTHORITY\NETWORK SERVICE' 登录失败。连接字符串属性无效 '
- 如何用gdi+做一个类似建模工具(EA)的绘图程序?谁有类似源码共享或者出售?
- 急问: 如何从vss中分离程序?
- 用户登陆问题 .NET+ACCESS+C#
- 为什么C#要把事件分为Click/MouseClick以及DoubleClick/MouseDoubleClick?
- 心情极其低落-散分
- 刚开始看.net,大家能不能给我介绍一些C#的书籍,最好是正式版的.net书籍!!谢谢!!
- 用C#做的VS.NET Addins
- 求VB翻译成C#
- C# 执行sql文件将数据导入到oracle数据库中
说得不清楚
我猜测:
因为你的程序里已经使用了MyRegexTextBox的方法啊属性啊
如果你删除了,那当然会报错啊