1.---------------------
作textbox的KeyPress中:
private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 8))
e.Handled = true;
base.OnKeyPress(e);}说明:
e.KeyChar != 8是为了让退格键起作用2.-----------------------------
If somebody use copy/paste, It also can paste something into the textbox, so and the following code to textchange event.private void textBox1_TextChanged(object sender, System.EventArgs e)
{
if(!System.Text.RegularExpressions.Regex.IsMatch(textBox1.Text,@"^\d*$"))textBox1.Undo();
}
作textbox的KeyPress中:
private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 8))
e.Handled = true;
base.OnKeyPress(e);}说明:
e.KeyChar != 8是为了让退格键起作用2.-----------------------------
If somebody use copy/paste, It also can paste something into the textbox, so and the following code to textchange event.private void textBox1_TextChanged(object sender, System.EventArgs e)
{
if(!System.Text.RegularExpressions.Regex.IsMatch(textBox1.Text,@"^\d*$"))textBox1.Undo();
}
解决方案 »
- ASP.NET(C#)实现在文本框中按回车后响应按钮提交
- 【请教】如果设置在关闭IE时清空cookie
- 用Ajax实现即时提示
- 高分求条码打印问题~~用BarcodeControl做过条码打印的高手请进.需要您的太忙..在线等.急急....
- VS中,关于解决方案的疑问
- 想学c#3d游戏开发,有谁教我怎么把开发平台搭起来,要用什么软件???
- 如何將數據綁定到Combo控件啊?
- 谁能解释一下 System.Collections.Generic 下的集合类为什么都不实现 ICloneable 了
- 高手请进,怎样控制datagrid中某一个单元的样式
- 紧急求助:DataSet里Table的Select方法用日期字段做条件为什么不行啊
- DataGrid如何绑定显示一个对象集合?
- 求救,为什么我找不到WMI的命名空间System.Management
加入RegularExpressionValidator 控件
ValidationExpression \d*