private bool IsNumeric(object value)
{
try
{
double d = System.Double.Parse(value.ToString(), System.Globalization.NumberStyles.Any);
return true;
}
catch (FormatException)
{
return false;
}
}MessageBox.Show((IsNumeric(textBox.Text)).ToString());
{
try
{
double d = System.Double.Parse(value.ToString(), System.Globalization.NumberStyles.Any);
return true;
}
catch (FormatException)
{
return false;
}
}MessageBox.Show((IsNumeric(textBox.Text)).ToString());
int nData;
try
{
nData=int.Parse(textBox1.text);
}
catch
{}2、每个字符判断,如下:
string strData=textBox1.text;
for(int i=0;i<strData.Length;i++)
if(!char.IsNumber(strData[i])
{
MessageBox.Show("不是数字字符");
break;
}