求助大家,一个TEXTBOX,往里边输入整数,当输入的数不是整数

来源:百度知道 编辑:UC知道 时间:2024/06/08 06:20:25
(包括字符等)或输入的数大于40,然后弹出个对话框,对话框里显示“请输入正确的数值”,并把TEXTBOX清空,这个该怎么写?
求助大家,积分没有了,谢谢了。我用的是Microsoft Visual Studio 2005

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

namespace WindowsApplication1
{
public partial class NumsForm : Form
{
public NumsForm()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
string str=this.textBox1.Text.Trim();
isDigit(str);

}

public bool isDigit(string str) {
char [] cs=str.ToCharArray();
foreach (char c in cs)
{
if ((!char.IsDigit(c)) && ((Convert.ToInt32(c)) > 40))
{
MessageBox.Show("请输入正确数值");
return false;
}
}
return