if (!Char.IsLetterOrDigit(e.KeyChar) && !Char.IsPunctuation(e.KeyChar) && !Char.IsControl(e.KeyChar) && e.KeyChar != (char)Keys.Back)   //IsNumber仅数字
            {
                e.Handled = true; //获取或设置一个值,指示是否处理过System.Windows.Forms.Control.KeyPress事件
            }
            else if (Char.IsPunctuation(e.KeyChar))
            {
                if (e.KeyChar == '.')
                {
                    if (((TextBox)sender).Text.LastIndexOf('.') != -1)
                    {
                        e.Handled = true;
                    }
                }
                else
                {
                    e.Handled = true;
                }
            }
           
           
限制输入类型 IsNumber是仅数字   IsLetterOrDigit是英文字母和数字  IsPunctuation是标点符号  Back是键盘回格键
些列小数点可用

 

 

 

 

-----------------------------------------------------------

 private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar >= (char)Keys.D0 && e.KeyChar <= (char)Keys.D9 || e.KeyChar == (char)Keys.Back)
            {
                e.Handled = false;
            }
            else
            {
                e.Handled = true;
            }
        }
 限制文本框输入类型只能输入数字

posted on 2009-02-12 16:21  也风  阅读(232)  评论(0编辑  收藏  举报