日期:2009-07-10  浏览次数:20404 次

本人在应用C#做项目的时候有感于,TextBox的文本框中的数值类型的判断不方便,在C#BBS中查找是否有这样的类或函数,可惜我失望了!于是凭着愚钝的脑袋写了一个,测试情况还很满意,拿让网友指点一二,如果有比较好的,望不惜赁教!shixiang9076@sina.com。


using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WinMarket
{
/// <summary>
/// Classfun 的摘要说明。
/// </summary>
public class Classfun
{
private bool IsBool;

public Classfun()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
//----------判断是否是整数 -----------------
public bool IsInt(string TBstr)
{
// string sign="+-";
string Intstr="1234567890";
string IntSign;
int IntstrSub,Intindex;
int intbool=0;
// TBstr=TBstr.Trim();
if(TBstr.Length==1)
{
IntstrSub=Intstr.IndexOf(TBstr);
if(IntstrSub!=-1)
{
intbool=0;
}
else
{
intbool=1;
}
}
else if(TBstr.Length>1)
{ Intindex=TBstr.IndexOf(".");
if(Intindex==-1)
{
for(int i=0;i<=TBstr.Length-1;i++)
{
IntSign= TBstr.Substring(i,1).ToString();
IntstrSub=Intstr.IndexOf(IntSign);
if(i==0)
{
if(IntstrSub!=-1)
{
if(IntstrSub!=9)
{
intbool=0;
}
else
{
intbool=i+1;
break;
}
}
else
{
if(IntSign=="-"||IntSign=="+")
{
intbool=0;

}
else
{
intbool=i+1;
break;
}
}

}
else
{
if(IntstrSub!=-1)
{
intbool=0;
}
else
{
intbool=i+1;
}

}
}


}

else
{
intbool=1;
}
}

if(intbool==0)
{
IsBool=true;
}
else
{
IsBool=false;
}
return IsBool;

}



}
}