用简单的方法验证在TextBox中输入二进制数
2013-05-23 18:52
204 查看
private void TextBox1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode != Keys.D0 && e.KeyCode != Keys.D1 && e.KeyCode != Keys.NumPad0 && e.KeyCode != Keys.NumPad1)//只允许输入0、1包括数字键盘处0、1值和退格键。无法保证输入中文,可以在转换成整形时捕获异常 { e.SuppressKeyPress = true;//不符合要求不显示在TextBox1中 } }
private void Button1_Click(object sender, EventArgs e) { try { UInt16 value= Convert.ToUInt16(SolenoidValveStatusTb.Text.ToString(), 2); if (value > 65535 || value < 0) { MessageBox.Show("电磁阀状态范围为0~65535"); } } catch (Exception err) { MessageBox.Show(err.ToString(), "warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); TextBox1.Clear(); } finally { PC_USBComunication.Produce(o); } }
相关文章推荐
- TextBox中只能输入数字的简单方法(C#)
- 验证输入内容是否为数字的简单方法
- textBox文本框中只能输入数字的最简单的方法
- textbox只能输入数字或中文的常用正则表达式和验证方法
- c#正则表达式验证TextBox输入的门牌号的方法,比如A12H代表A栋12层H户
- JS简单验证上传文件类型的方法
- Asp.net如何验证TextBox控件只输入数字(五种情况分析)转帖
- 验证输入的是否数字的几种方法
- TextBox获取输入焦点时自动全选的实现方法
- TextBox只能输入数字的最简洁方法!
- 使用Kendo 输入验证的几种方法
- 解析使用js判断只能输入数字、字母等验证的方法(总结)
- Asp.net TextBox常规输入验证
- C#按回车Enter使输入焦点自动跳到下一个TextBox的方法收集
- 利用String类或StringBuffer类的方法,对输入的Email地址进行有效性验证。
- android 验证文本框是否输入字符的方法
- java简单实现双色球彩票模拟实例(数组、排序、方法、随机数、键盘输入)
- jquery实现用户信息修改验证输入方法汇总
- C#中TextBox实现输入提示功能的方法