WinFrom 中TextBox只能输入数字、小数点

        private void txtIVQ_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextBox txt = (TextBox)sender;
            //只能输入1次小数点
            if (e.KeyChar == 46 && txt.Text.Contains("."))
            {
                e.Handled = true;
                //e.KeyChar = (char)0;
                return;
            }
            //只能输入.或数字
            if (e.KeyChar != 46 && e.KeyChar < 48 || e.KeyChar > 57)
            {
                e.Handled = true;
                //e.KeyChar = (char)0;
                return;
            }
        }



 
posted @ 2010-07-01 17:24  BoyceLyu  阅读(629)  评论(1编辑  收藏  举报