如何让一个TextBox控件只接受货币数字? C#中不能用正则表达式,VB是可以的。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 KillCat你的Regex.Match是什么意思,看不懂。Vs.Net中help连你写的关键字都查不到,是否是简写,拜托写清楚些好吗?不胜感激!!! private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { switch(e.KeyChar) { case '$': { if(((TextBox)sender).Text.Length > 0) { e.Handled = true; } break; } case '.': { if(((TextBox)sender).Text.IndexOf(".") > 0) { e.Handled = true; } break; } case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '0': { break; } default: { e.Handled = true; break; } }//switch } switch (Style) { case uTextBox_style.Numeric: string strSymbol="-+."; if ((Char.IsDigit(e.KeyChar)) | (Char.IsControl(e.KeyChar)) | (strSymbol.IndexOf(e.KeyChar.ToString())!=-1)) { } else { e.Handled=true; } break; } C#里面访问OPC时编译错误。进去看 WPF中使用MVVM如何改变绑定的数据源? 求C#中的HttpWebRequest 例子? 问个关于程序集的问题 XML 如何获取xml节点的穿透任意层次的“根节点”?高分求救!!! C#的学习路程 C#串行端口通信问题 用C#如何保留到小数点后两位? 网络安全,云起云涌 C#未能加载文件或程序集 C#:web页面上如何实现类同于WINDOWS FORM的openfiledialog功能? this操作数的作用,在线急等
{
switch(e.KeyChar)
{
case '$':
{
if(((TextBox)sender).Text.Length > 0)
{
e.Handled = true;
} break;
}
case '.':
{
if(((TextBox)sender).Text.IndexOf(".") > 0)
{
e.Handled = true;
} break;
}
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '0':
{
break;
}
default:
{
e.Handled = true;
break;
}
}//switch
}
{
case uTextBox_style.Numeric:
string strSymbol="-+.";
if ((Char.IsDigit(e.KeyChar)) | (Char.IsControl(e.KeyChar)) | (strSymbol.IndexOf(e.KeyChar.ToString())!=-1))
{
}
else
{
e.Handled=true;
}
break;
}