zoukankan      html  css  js  c++  java
  • c#文本框限制输入内容

     
     
     //限制输入不能为中文和全角
            private void zhbh_KeyPress(object sender, KeyPressEventArgs e)
            {
                int chfrom = Convert .ToInt32("4e00", 16);    //范围(0x4e00~0x9fa5)转换成int(chfrom~chend)
                int chend = Convert .ToInt32("9fa5", 16);
                if (e.KeyChar >= (Char )chfrom && e.KeyChar <= (Char)chend)
                {
                    e.Handled = true;
                }
                if (e.KeyChar >= (Char )65281 & (int)e.KeyChar <= ( Char)65374)
                {
                    e.Handled = true;
                }
            }
     
    //*******以下方法需在文本框的KeyPress方法下调用
            //限制输入只能为数字
            private void wz_qsh_KeyPress(object sender, KeyPressEventArgs e)
            {
                if (!(Char .IsNumber(e.KeyChar)) && e.KeyChar != (Char)8)
                {
                    e.Handled = true;
                }
            }
     /**
             * 限制只能输入数字和小数点
             * */
            public void validationOnlyFloat(KeyPressEventArgs e, TextBox t)
            {
                if (((int )e.KeyChar < 48 || (int)e.KeyChar > 57) && ( int)e.KeyChar != 8 && (int )e.KeyChar != 46)
                    e.Handled = true;
                //小数点的处理。
                if ((int )e.KeyChar == 46)                           //小数点
                {
                    if (t.Text.Length <= 0)
                        e.Handled = true;   //小数点不能在第一位
                    else
                    {
                        float f;
                        float oldf;
                        bool b1 = false , b2 = false;
                        b1 = float.TryParse(t.Text, out oldf);
                        b2 = float.TryParse(t.Text + e.KeyChar.ToString(), out f);
                        if (b2 == false )
                        {
                            if (b1 == true )
                                e.Handled = true;
                            else
                                e.Handled = false;
                        }
                    }
                }
            }
  • 相关阅读:
    lightoj 1151 Snakes and Ladders 期望 高斯消元
    lightoj 1104 Birthday Paradox 概率
    lightoj 1079 Just another Robbery 概率 背包
    集合的划分
    线性筛法
    学姐出的毒奶题之yjj
    [poj] 1149 PIGS || 最大流经典题目
    [poj] 3057 Evacuation
    [poj] 1273 Drainage Ditches
    [poj] 2891 Strange Way to Express Integers
  • 原文地址:https://www.cnblogs.com/yanjinliang/p/5916457.html
Copyright © 2011-2022 走看看