private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            //IsNumber判断输入的是不是数字
            //e.KeyChar != (char)Keys.Back 判断输入的是不是退格

            if (!(Char.IsNumber(e.KeyChar)) && e.KeyChar != (char)Keys.Back)
            {
                e.Handled = true;
                this.errorProvider1.SetError(textBox1, "请输入数字");               
            }
            else
            {
                Int64 r = 1;
                if (Int64.TryParse(textBox1.Text.ToString(), out r))
                {
                    this.errorProvider1.Dispose();
                }                
            }
        }


本文转载:CSDN博客