C#中textbox只能输入数字
2011-06-21 10:01
267 查看
textbox只能输入数字
方法一:
private void textBox7_KeyPress(object sender, KeyPressEventArgs e)//只能输入数字和.
{
byte[] array = System.Text.Encoding.Default.GetBytes(e.KeyChar.ToString());
if (!char.IsDigit(e.KeyChar) || array.LongLength == 2) e.Handled = true;
if (e.KeyChar == '/b' || e.KeyChar == '.') e.Handled = false;
}
方法二:
private void textBox7_KeyPress(object sender, KeyPressEventArgs e)//只能输入数字和. 但不能输入小数
{
if (!(e.KeyChar >= '0' && e.KeyChar <= '9')) e.Handled = true;
if (e.KeyChar == '/b' || e.KeyChar == '.') e.Handled = false;
}
方法三:
private void textBox7_KeyPress(object sender, KeyPressEventArgs e)//需求数量栏位,只能输入数字,并且可以输入小数
{
if (e.KeyChar != 13 && e.KeyChar != 8 && !char.IsDigit(e.KeyChar) && e.KeyChar != 46) e.Handled = true;
int a = textBox7.Text.IndexOf('.');
if (e.KeyChar == 46 && a > 0) e.Handled = true;
}
方法一:
private void textBox7_KeyPress(object sender, KeyPressEventArgs e)//只能输入数字和.
{
byte[] array = System.Text.Encoding.Default.GetBytes(e.KeyChar.ToString());
if (!char.IsDigit(e.KeyChar) || array.LongLength == 2) e.Handled = true;
if (e.KeyChar == '/b' || e.KeyChar == '.') e.Handled = false;
}
方法二:
private void textBox7_KeyPress(object sender, KeyPressEventArgs e)//只能输入数字和. 但不能输入小数
{
if (!(e.KeyChar >= '0' && e.KeyChar <= '9')) e.Handled = true;
if (e.KeyChar == '/b' || e.KeyChar == '.') e.Handled = false;
}
方法三:
private void textBox7_KeyPress(object sender, KeyPressEventArgs e)//需求数量栏位,只能输入数字,并且可以输入小数
{
if (e.KeyChar != 13 && e.KeyChar != 8 && !char.IsDigit(e.KeyChar) && e.KeyChar != 46) e.Handled = true;
int a = textBox7.Text.IndexOf('.');
if (e.KeyChar == 46 && a > 0) e.Handled = true;
}
相关文章推荐
- c# Textbox 只能输入数字
- C#textbox只能输入数字和小数点
- [导入]C#中TextBox只能输入数字的代码
- C#中winform控制textbox输入只能为数字的方法
- TextBox中只能输入数字的几种常用方法(C#)
- C#textbox只能输入数字
- C#设置textBox只能输入数字(正数,负数,小数)简单实现
- C#设置textBox只能输入数字(正数,负数,小数)简单实现
- C#验证:限制TextBox只能输入数字并控制输入数字的长度(数字)
- TextBox中只能输入数字的简单方法(C#)
- C#textbox只显示数字,只能输入数字
- C#的winform中控制TextBox中只能输入数字(加上固定位数和首位不能为0)
- C# TextBox中只能输入数字的几种常用方法(C#)
- C#Winform限制Textbox只能输入数字
- C#限制TextBox只能输入数字
- Winform TextBox中只能输入数字的几种常用方法(C#)
- C#的winform中控制TextBox中只能输入数字?
- Winform TextBox中只能输入数字的几种常用方法(C#)
- C#中TextBox只能输入数字的代码
- 用C#编写的Windows应用程序如何控制TextBox中只能输入数字?