WinForm-TextBox只能输入数字

        /// <summary>
        /// 只能输入数字
        /// </summary>
        private void txt1_KeyPress(object sender, KeyPressEventArgs e)
        {
            //如果输入的不是退格和数字,则屏蔽输入
            if (!(e.KeyChar == 8 || (e.KeyChar >= 48 && e.KeyChar <= 57)))  // 小数点为46
            {
                e.Handled = true;
            }
        }
posted @ 2022-01-05 17:37  ꧁执笔小白꧂  阅读(127)  评论(0编辑  收藏  举报