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;

            }

        }





 

你可能感兴趣的:(只能输入数字)