文本框只能输入数字

  private void txtSum_KeyPress(object sender, KeyPressEventArgs e)
        {
          

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

            }


        }

原文地址:https://www.cnblogs.com/haimingkaifa/p/5605799.html