zoukankan      html  css  js  c++  java
  • 限制输入类型

     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;
                }
            }
     限制文本框输入类型只能输入数字

  • 相关阅读:
    随机产生字母a--z, A-Z 的任意组合
    如何获取HttpServletResponse里面的内容
    线上问题:如何定位解决CPU高占有率
    tomcat+apache 实现负载均衡之一:同一台电脑部署2个以上tomcat
    drozer与adb工具的安装与使用
    CVE-2012-0002(MS12-020)3389远程溢出漏洞
    VMware每次联网都需要还原默认设置解决办法
    Ubuntu设置右键打开终端
    Metasploits之Adobe阅读器漏洞
    Metasploits之ms10_018
  • 原文地址:https://www.cnblogs.com/zzh1236/p/1389190.html
Copyright © 2011-2022 走看看