zoukankan      html  css  js  c++  java
  • 在文本框(TextBox)中只接受数字和小数点的输入(引自:zyg19800719的专栏)

     //KeyPress事件:当控件获得焦点,并且用户按下且释放键盘上的键后发生
            private void textBox1_KeyPress(object sender, KeyPressEventArgs e)//文本框只接受数字的输入和小数点
            {
                
    //IsNumber:指定字符串中位于指定位置的字符是否属于数字类别
                
    //IsPunctuation:指定字符串中位于指定位置的字符是否属于标点符号类别
                
    //IsControl:指定字符串中位于指定位置的字符是否属于控制字符类别
                if (!Char.IsNumber(e.KeyChar) && !Char.IsPunctuation(e.KeyChar) && !Char.IsControl(e.KeyChar))
                {
                    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;
                    }
                }
            }
  • 相关阅读:
    wp8使用mvvm模式简单例子(二)---登陆功能,事件触发
    wp8使用mvvm模式简单例子
    win8.1使用WP8SDK出现Windows Phone Emulator无法启动的问题解决方案
    asp.net原理笔记----页面控件类型,页面状况和asp.net编译过程
    asp.net生命周期
    asp.net服务器数据源控件学习笔记
    AJax学习笔记
    asp.net敏感词过滤
    网上书城总结笔记
    在自己的网站上使用RSS订阅功能
  • 原文地址:https://www.cnblogs.com/perfect/p/571093.html
Copyright © 2011-2022 走看看