如何让wpf 中的textbox只能输入整型或浮点型
来源:互联网 发布:python socket服务端 编辑:程序博客网 时间:2024/06/03 12:52
不使用正则表达式
bool isNotnum = false; private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { ((TextBox)sender).ImeMode = ImeMode.Disable; this.isNotnum = false; ((TextBox)sender).Tag = ((TextBox)sender).Text; //允许输入数字、小数点和删除键 if((e.KeyChar<48||e.KeyChar>57) && e.KeyChar!=8&&e.KeyChar!=(char)('.')) { e.Handled = true; this.isNotnum = true; } //小数点只能输入一次 if(e.KeyChar ==(char)('.')&&((TextBox)sender).Text.IndexOf('.')!=-1) { e.Handled = true; } //第一位不能为小数点 if (e.KeyChar == (char)('.') && ((TextBox)sender).Text == "") { e.Handled = true; } //第一位是0,第二位必须为小数点 if (e.KeyChar != (char)('.') && ((TextBox)sender).Text == "0") { e.Handled = true; } if(e.KeyChar == 8) { e.Handled = false; } //只允许输入数字 if (e.KeyChar >= 0x4e00 && e.KeyChar <= 0x9fa5) { this.isNotnum = true; } } private void textBox1_KeyUp(object sender, KeyEventArgs e) { if (this.isNotnum && ((TextBox)sender).Text != ((TextBox)sender).Text.ToString()) { MessageBox.Show("只能输入数字!!!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Question); ((TextBox)sender).Text = ((TextBox)sender).Tag.ToString(); ((TextBox)sender).SelectionStart = ((TextBox)sender).Text.Length; this.isNotnum = false; return; } } }
- 如何让wpf 中的textbox只能输入整型或浮点型
- wpf怎么让Textbox只能输入数字?
- 如何控制TextBox只能输入英文或只能输入汉字?
- WPF TextBox只能输入数字
- 让textbox只能输入数字
- 如何让TextBox只能输入数字、汉字、字母?
- c# 如何让textbox只能输入数字和小数
- 只能输入浮点数值的TextBox
- 控制TextBox只能输入浮点数
- wpf textbox控制只能输入数字
- Delphi中如何让编辑框只能输入数字或者只能输入一个浮点数值呢?
- 让TextBox只能输入数字和小数点
- TextBox限制只能输入字母或数字
- 如何控制TextBox控件只能输入数值型字符串
- 文本框只能输入数值或浮点数
- 如何使TextBox只能输入数字?
- 如何使TextBox只能输入数字?
- C#如何让TEXTBOX只能输入英文状态下的数字并且限制位数
- GCD实战一:使用串行队列实现简单的预加载
- Jave 模拟 http 请求
- GCD实战2:资源竞争
- Timer和spring的Quartz两种定时器的区别。
- Linux进程及进程通讯
- 如何让wpf 中的textbox只能输入整型或浮点型
- 暮色中勤奋依旧—成都传智播客自习记
- PopupWindow
- hadoop二次排序一
- shell读取文件 随机读取
- Message List 一次性输出多个消息
- web.config connectionStrings 数据库连接字符串的解释(转载)
- 关于c++中类的继承与派生
- Android大话设计模式 第三章----开放封闭原则---孙悟空任弼马温一职