阅读背景:

C# 文本输入限制类型,datagridview单元格输入验证

来源:互联网 

1.只能输入double类型

  private void textBoxX6_KeyPress(object sender, KeyPressEventArgs e)
        {
            {
                //数字0~9所对应的keychar为48~57,小数点是46,Backspace是8  
                e.Handled = true;
                //输入0-9和Backspace del 有效  
                if ((e.KeyChar >= 47 && e.KeyChar <= 58) || e.KeyChar == 8)
                {
                    e.Handled = false;
                }
                if (e.KeyChar == 46)                       //小数点        
                {
                    if (textBoxX6.Text.Length <= 0)
                        e.Handled = true;           //小数点不能在第一位        
                    else
                    {
                        float f;
                        if (float.TryParse(textBoxX6.Text + e.KeyChar.ToString(), out f))
                        {
                            e.Handled = false;
                        }
                    }
                }
            }  
  private void textBoxX6_K



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: