怎么判断一个textbox的输入是float型的? 也就是可以转换成float型,3x! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 float.Parse(this.TextBox1.Text.Trim()) 用Parse是比较精确的,用其他的本身具有强制转换功能,可能会造成数据和原来的不一样了。 private void textBox1_Leave(object sender, EventArgs e){ try { float.Parse(textBox1.Text.Trim()); } catch { MessageBox.Show("请输入float"); textBox1.Select(); }} 我是想判断用户输入是否合法啊,否则会parse或convert出错难道必须用try catch 来确定用户输入是否是个float型吗?? using System.Text .RegularExpressions ;private void textBox1_Leave(object sender, System.EventArgs e) { string moban=@"^[+-]?\d+\.(\d)+$"; if(!Regex .IsMatch (textBox1 .Text ,moban)) MessageBox .Show ("please input float type!"); } 不好意思,用的是日文vs,把里面的 钱的 符号斗换成 \ 就可以了using System.Text .RegularExpressions ;private void textBox1_Leave(object sender, System.EventArgs e) { string moban=@"^[+-]?\d+\.(\d)+$"; if(!Regex .IsMatch (textBox1 .Text ,moban)) MessageBox .Show ("please input float type!"); } C# 图片打印文字质量问题 DataTable 去掉重复行 form1.InnerHtml赋值前台不显示 c#中的添加引用 问题 gif进度条问题! C#里面有这样的语法规则吗? treeview 如何设置让节点不能点击 但是能点击展开按钮 救命啊!TreeView显示的不是树的问题 C#打包的问题 用中文变量!! 彻底改变程序的易读性(搞笑). 谁能告诉我有关c#或asp.net或web service的外文文献或文章呀? 300 高分求 winform,源程序(c#),erp 相关 最好
{
try
{
float.Parse(textBox1.Text.Trim());
}
catch
{
MessageBox.Show("请输入float");
textBox1.Select();
}
}
难道必须用try catch 来确定用户输入是否是个float型吗??
{
string moban=@"^[+-]?\d+\.(\d)+$";
if(!Regex .IsMatch (textBox1 .Text ,moban))
MessageBox .Show ("please input float type!");
}
{
string moban=@"^[+-]?\d+\.(\d)+$";
if(!Regex .IsMatch (textBox1 .Text ,moban))
MessageBox .Show ("please input float type!");
}