在软件开发时,经常面临数值类型数据的输入,如和限定文本框只能输入数值型数据,是一件麻烦事情。开发一个只能输入数值型数据的文本框可以简化很多开发工作,其代码如下,供参考。
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace PRisk
{
class TextBoxForDigit:TextBox
{
public ToolTip toolTip=new ToolTip() ;
public double max;
public double min;
public string tip = "输入数字型数据";
public TextBoxForDigit()
{
this.Validating +=
new System.ComponentModel.CancelEventHandler(NumberValidating);
this.MouseHover += new System.EventHandler(mMouseHover);
toolTip.SetToolTip(this , tip);