本文介绍了用户可以在文本框中键入Only Numeric values的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何解决此问题
How can I solve this problem
private void txtTestingNumeric_TextChanged(object sender, EventArgs e)
{
if (System.Text.RegularExpressions.Regex.IsMatch("[^0-9]", txtTestingNumeric.Text))
{
MessageBox.Show("Please enter only numbers.");
txtTestingNumeric.Text.Remove(txtTestingNumeric.Text.Length - 1);
}
}
请帮助我
提前感谢
Please help me
thanks in advance
推荐答案
private void txtTestingNumeric_KeyPress(object sender, KeyPressEventArgs e)
{
int ascii = e.KeyChar;
if ((ascii >= 48 && ascii <= 57) || ascii == 8 || ascii == 13 || ascii==46)
{
e.Handled = false;
}
else
{
e.Handled = true;
}
}
private void TectBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if ((e.KeyChar >= 48 && e.KeyChar <= 57) )
{
e.Handled = false;
}
else
{
e.Handled = true;
}
}
private void txttax1_KeyPress(object sender, KeyPressEventArgs e)
{
if ((e.KeyChar >= 48 && e.KeyChar <= 57) || (e.KeyChar == 32) || (e.KeyChar == 8))
{
e.Handled = false;
}
else
{
e.Handled = true;
}
}
这篇关于用户可以在文本框中键入Only Numeric values的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!