C# winform中TextBox控件只能输入数字

来源:互联网 发布:c语言运行命令 编辑:程序博客网 时间:2024/06/12 01:53

 添加textbox的keyPress事件

private void txtSum_KeyPress(object sender, KeyPressEventArgs e)

        {
            if ((e.KeyChar != 8 && !char.IsDigit(e.KeyChar))&&e.KeyChar!=13)
            {
                MessageBox.Show("商品数量只能输入数字","操作提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
                e.Handled = true;
            }
        }
0 0
原创粉丝点击