如何判断文本匡的文本是字符串,还是数字? 用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中编程,使它只接受数字输入 XP机器上安装了vs2008,在form上添加一个水晶报表控件。 C# 链接mysql数据库 把访问太快的IP自动屏蔽掉 第一次建立类库,请大家帮忙 怎样获得一个窗体上的所有组件 菜鸟提问--字符串截取问题? (在线等...) 如何自动调整Label的高度 OPC诸多问题,搞过的进来 为什么这段代码不能正确显示??? 如何得到一个mdb数据库的所有表,每一个表的所有字段? 在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中编程,使它只接受数字输入