如何判断文本匡的文本是字符串,还是数字? 用toint()转换成inttextbox.text就是字符穿 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public static bool IsNumber(char c); 你在csdn里搜索一下,这样的帖子以前有很多的。 如果是.net就可以使用约束规则了 bool lb=false; for(int i=0;i<textBox1.Text.Length;i++) if(Char.IsNumber(textBox1.Text,i)) { lb=true; break; } if(lb) MessageBox.Show("number"); else MessageBox.Show("no number"); 这样只能判断int;加一个条件,判断"."bool lb=false;int dot=0;if(textBox1.text[0]=="."){lb=false;...//out no number return}for(int i=0;i<textBox1.Text.Length;i++){if(textBox1.text[0]=="."){dot ++;}if(Char.IsNumber(textBox1.Text,i)){lb=true;break;}}if(lb&&dot<=1)MessageBox.Show("number");elseMessageBox.Show("no number"); ft:bool lb=false;int dot=0;if(textBox1.text[0]=="."){lb=false;...//out no numberreturn}for(int i=0;i<textBox1.Text.Length;i++){if(textBox1.text[i]==".")//刚刚错了 应该是text[i] hehe{dot ++;}if(Char.IsNumber(textBox1.Text,i)){lb=true;break;}}if(lb&&dot<=1)MessageBox.Show("number");elseMessageBox.Show("no number"); ft我是starcbh不用检查"."也行,你test一下. 用ISNUMBER()进行判断即可! 转换个想法嘛: try { int iTtmp=Int16,parse(textbox1.text.tostring()); } catch { MessageBox.Show("您输入的不是数字"); textBox1.focus(); return; } 其实这中方法在其它语言中也是通用的。当然你也可以在textBox的keydown中编程,使它只接受数字输入 从XML读入的字符串包含的换行符不能识别 冰天雪地跪求system.InvalidOperationException异常 正则图片格式 C#.net 引入Xceed grid for wpf v3.0 问题 求助C#发送XML数据的问题!! 图表控件,着急上火啊 水晶报表打印时让行随字数的增多自动加高,并且想用空行填充空白的页面。 <a>中的title问题--奇怪的问题 C#中的公共静态成员的问题 我的msdn不行了!!! 在xp下安装rc3英文版有错误,请帮我解决 (mm系列问题)一个百思不得其解的问题
for(int i=0;i<textBox1.Text.Length;i++)
if(Char.IsNumber(textBox1.Text,i))
{
lb=true;
break;
}
if(lb)
MessageBox.Show("number");
else
MessageBox.Show("no number");
int dot=0;
if(textBox1.text[0]==".")
{
lb=false;
...//out no number
return
}
for(int i=0;i<textBox1.Text.Length;i++)
{
if(textBox1.text[0]==".")
{
dot ++;
}if(Char.IsNumber(textBox1.Text,i))
{
lb=true;
break;
}
}
if(lb&&dot<=1)
MessageBox.Show("number");
else
MessageBox.Show("no number");
int dot=0;
if(textBox1.text[0]==".")
{
lb=false;
...//out no number
return
}
for(int i=0;i<textBox1.Text.Length;i++)
{
if(textBox1.text[i]==".")//刚刚错了 应该是text[i] hehe
{
dot ++;
}if(Char.IsNumber(textBox1.Text,i))
{
lb=true;
break;
}
}
if(lb&&dot<=1)
MessageBox.Show("number");
else
MessageBox.Show("no number");
try
{
int iTtmp=Int16,parse(textbox1.text.tostring());
}
catch
{
MessageBox.Show("您输入的不是数字");
textBox1.focus();
return;
}
当然你也可以在textBox的keydown中编程,使它只接受数字输入