实现textBox只能输入数字的一种方法!

在KeyPress事件中加入以下代码即可      
  private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((e.KeyChar != 8 && !char.IsDigit(e.KeyChar)) && e.KeyChar != 13)
            {
                MessageBox.Show("商品数量只能输入数字!");
                e.Handled = true;//表示已经处理过该KeyPress事件
            }

        }

原文地址:https://www.cnblogs.com/hrx521/p/1044886.html