如何使文本框仅接受数字和小数? [英] How do you make a text-box only accept numbers and decimals?
本文介绍了如何使文本框仅接受数字和小数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何使文本框仅接受1s,2s,3s,4s,5s,6s,7s,8s,9s,0s和.s.
I''m wondering how to make a text-box only accept 1s, 2s, 3s, 4s, 5s, 6s, 7s, 8s, 9s, 0s, and.s.
推荐答案
private void tbacc_Receipt_nAmount_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsDigit(e.KeyChar) && e.KeyChar != '.')
{
e.Handled = true;
}
if (!char.IsControl(e.KeyChar))
{
TextBox textbox = (TextBox)sender;
if (textbox.Text.IndexOf('.') > -1 &&
textbox.Text.Substring(textbox.Text.IndexOf('.')).Length >= 3)
{
e.Handled = true;
}
}
}
您尝试了什么? [
http://www.csharpfriends.com/Forums/ShowPost.aspx?PostID=79881 [ http://www.pcreview.co.uk/forums/textbox-only-numbers-and-decimal-seperator-t3667663.html [ NumericTextBox(C#.NET) [ ^ ]http://www.csharpfriends.com/Forums/ShowPost.aspx?PostID=79881[^]
http://www.pcreview.co.uk/forums/textbox-only-numbers-and-decimal-seperator-t3667663.html[^]
NumericTextBox (C#.NET)[^]
这篇关于如何使文本框仅接受数字和小数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文